
    <html lang="zh-CN">
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
      <body class="nodata " style="">    
     
        <main style="width:100%">  
        <div class="blog-content-box"> 
            <div class="article-title-box">
                <h1 class="title-article" id="articleContentId">使用Laravel实现内容管理系统项目</h1>
            </div><div id="article_content" class="article_content clearfix">
        <link rel="stylesheet" href="https://csdnimg.cn/release/blogv2/dist/mdeditor/css/editerView/kdoc_html_views-1a98987dfd.css">
        <link rel="stylesheet" href="https://csdnimg.cn/release/blogv2/dist/mdeditor/css/editerView/ck_htmledit_views-044f2cf1dc.css">
                <div id="content_views" class="htmledit_views">
                    <p id="main-toc"><strong>目录</strong></p> 
<p id="" style="margin: 0px 0px 2px 48px; padding-left: 24px;"><a href="#t0" rel="nofollow" target="_self">项目介绍</a></p> 
<p id="" style="margin: 0px 0px 2px 48px; padding-left: 24px;"><a href="#t1" rel="nofollow" target="_self">安装Laravel</a></p> 
<p id="" style="margin: 0px 0px 2px 48px; padding-left: 24px;"><a href="#t2" rel="nofollow" target="_self">配置文件&nbsp;</a></p> 
<p id="" style="margin: 0px 0px 2px 48px; padding-left: 24px;"><a href="#t3" rel="nofollow" target="_self">引入需要的静态文件</a></p> 
<p id="" style="margin: 0px 0px 2px 48px; padding-left: 24px;"><a href="#t4" rel="nofollow" target="_self">一、后台用户登录&nbsp;</a></p> 
<p id="" style="margin: 0px 0px 2px 96px; padding-left: 24px;"><a href="#t5" rel="nofollow" target="_self">1.创建用户表</a></p> 
<p id="" style="margin: 0px 0px 2px 96px; padding-left: 24px;"><a href="#t6" rel="nofollow" target="_self">2.显示登录页面</a></p> 
<p id="" style="margin: 0px 0px 2px 96px; padding-left: 24px;"><a href="#t7" rel="nofollow" target="_self">3.Ajax交互</a></p> 
<p id="" style="margin: 0px 0px 2px 96px; padding-left: 24px;"><a href="#t8" rel="nofollow" target="_self">4.验证用户登录</a></p> 
<p id="" style="margin: 0px 0px 2px 96px; padding-left: 24px;"><a href="#t9" rel="nofollow" target="_self">&nbsp;5.用户退出</a></p> 
<p id="" style="margin: 0px 0px 2px 48px; padding-left: 24px;"><a href="#t10" rel="nofollow" target="_self">二、后台首页</a></p> 
<p id="" style="margin: 0px 0px 2px 96px; padding-left: 24px;"><a href="#t11" rel="nofollow" target="_self">1.后台页面布局</a></p> 
<p id="" style="margin: 0px 0px 2px 96px; padding-left: 24px;"><a href="#t12" rel="nofollow" target="_self">2.显示后台首页</a></p> 
<p id="" style="margin: 0px 0px 2px 96px; padding-left: 24px;"><a href="#t13" rel="nofollow" target="_self">3.判断登录状态</a></p> 
<p id="" style="margin: 0px 0px 2px 48px; padding-left: 24px;"><a href="#t14" rel="nofollow" target="_self">三、栏目管理</a></p> 
<p id="" style="margin: 0px 0px 2px 96px; padding-left: 24px;"><a href="#t15" rel="nofollow" target="_self">1.创建栏目表</a></p> 
<p id="" style="margin: 0px 0px 2px 96px; padding-left: 24px;"><a href="#t16" rel="nofollow" target="_self">2.添加栏目</a></p> 
<p id="" style="margin: 0px 0px 2px 96px; padding-left: 24px;"><a href="#t17" rel="nofollow" target="_self">3.显示栏目列表</a></p> 
<p id="" style="margin: 0px 0px 2px 96px; padding-left: 24px;"><a href="#t18" rel="nofollow" target="_self">4.编辑栏目&nbsp;</a></p> 
<p id="" style="margin: 0px 0px 2px 96px; padding-left: 24px;"><a href="#t19" rel="nofollow" target="_self">5.删除栏目</a></p> 
<p id="" style="margin: 0px 0px 2px 48px; padding-left: 24px;"><a href="#t20" rel="nofollow" target="_self">四.内容管理</a></p> 
<p id="" style="margin: 0px 0px 2px 96px; padding-left: 24px;"><a href="#t21" rel="nofollow" target="_self">1.创建内容表</a></p> 
<p id="" style="margin: 0px 0px 2px 96px; padding-left: 24px;"><a href="#t22" rel="nofollow" target="_self">2.添加内容</a></p> 
<p id="" style="margin: 0px 0px 2px 96px; padding-left: 24px;"><a href="#t23" rel="nofollow" target="_self">3.上传图片</a></p> 
<p id="" style="margin: 0px 0px 2px 96px; padding-left: 24px;"><a href="#t24" rel="nofollow" target="_self">4.整合UFditor</a></p> 
<p id="" style="margin: 0px 0px 2px 96px; padding-left: 24px;"><a href="#t25" rel="nofollow" target="_self">5.显示内容列表</a></p> 
<p id="" style="margin: 0px 0px 2px 96px; padding-left: 24px;"><a href="#t26" rel="nofollow" target="_self">6.编辑内容</a></p> 
<p id="" style="margin: 0px 0px 2px 96px; padding-left: 24px;"><a href="#t27" rel="nofollow" target="_self">7.删除内容</a></p> 
<p id="" style="margin: 0px 0px 2px 48px; padding-left: 24px;"><a href="#t28" rel="nofollow" target="_self">五.广告位管理</a></p> 
<p id="" style="margin: 0px 0px 2px 96px; padding-left: 24px;"><a href="#t29" rel="nofollow" target="_self">1.创建广告位表</a></p> 
<p id="" style="margin: 0px 0px 2px 96px; padding-left: 24px;"><a href="#t30" rel="nofollow" target="_self">2.添加广告位</a></p> 
<p id="" style="margin: 0px 0px 2px 96px; padding-left: 24px;"><a href="#t31" rel="nofollow" target="_self">3.显示、编辑、删除广告位列表</a></p> 
<p id="" style="margin: 0px 0px 2px 48px; padding-left: 24px;"><a href="#t32" rel="nofollow" target="_self">六.广告内容管理</a></p> 
<p id="" style="margin: 0px 0px 2px 96px; padding-left: 24px;"><a href="#t33" rel="nofollow" target="_self">1.创建广告内容表</a></p> 
<p id="" style="margin: 0px 0px 2px 96px; padding-left: 24px;"><a href="#t34" rel="nofollow" target="_self">2.添加、显示、编辑、删除广告</a></p> 
<p id="" style="margin: 0px 0px 2px 48px; padding-left: 24px;"><a href="#t35" rel="nofollow" target="_self">&nbsp;结语</a></p> 
<p id="" style="margin: 0px 0px 2px 48px; padding-left: 24px;"><a href="#t36" rel="nofollow" target="_self">前台首页</a></p> 
<p id="" style="margin: 0px 0px 2px 96px; padding-left: 24px;"><a href="#t37" rel="nofollow" target="_self">一、页面布局</a></p> 
<p id="" style="margin: 0px 0px 2px 96px; padding-left: 24px;"><a href="#t38" rel="nofollow" target="_self">二、首页、栏目导航、轮播图、广告位、栏目内容展示</a></p> 
<p id="" style="margin: 0px 0px 2px 48px; padding-left: 24px;"><a href="#t39" rel="nofollow" target="_self">前台用户管理</a></p> 
<p id="" style="margin: 0px 0px 2px 96px; padding-left: 24px;"><a href="#t40" rel="nofollow" target="_self">用户注册、用户登录和用户退出</a></p> 
<p id="" style="margin: 0px 0px 2px 48px; padding-left: 24px;"><a href="#t41" rel="nofollow" target="_self">内容列表页</a></p> 
<p id="" style="margin: 0px 0px 2px 96px; padding-left: 24px;"><a href="#t42" rel="nofollow" target="_self">一、内容列表</a></p> 
<p id="" style="margin: 0px 0px 2px 96px; padding-left: 24px;"><a href="#t43" rel="nofollow" target="_self">二、面包屑导航</a></p> 
<p id="" style="margin: 0px 0px 2px 144px; padding-left: 24px;"><a href="#1.%E5%AE%89%E8%A3%85" rel="nofollow" target="_self">1.安装</a></p> 
<p id="" style="margin: 0px 0px 2px 144px; padding-left: 24px;"><a href="#2.%E9%85%8D%E7%BD%AE%E5%AF%BC%E8%88%AA" rel="nofollow" target="_self">2.配置导航</a></p> 
<p id="" style="margin: 0px 0px 2px 48px; padding-left: 24px;"><a href="#t44" rel="nofollow" target="_self">内容展示</a></p> 
<p id="" style="margin: 0px 0px 2px 96px; padding-left: 24px;"><a href="#t45" rel="nofollow" target="_self">一、内容详细页</a>​​​​​​​</p> 
<p></p> 
<hr id="hr-toc"> 
<p></p> 
<h3 id="%E9%A1%B9%E7%9B%AE%E4%BB%8B%E7%BB%8D"><a name="t0"></a>项目介绍</h3> 
<p>本项目分为<strong>前台</strong>和<strong>后台</strong>。前台的功能包括<strong>用户登录与注册</strong>、<strong>内容列表</strong>、<strong>内容详细页</strong>、<strong>广告展示</strong>、<strong>评论</strong>和<strong>热门内容</strong>等。后台在<strong>未登录</strong>的状态下会自动跳转至登录页面。输入用户名<strong>“admin”</strong>、密码<strong>“123456”</strong>和<strong>验证码</strong>后，单击<strong>“登录”</strong>按钮，即可进行登录。登录后，页面顶部<strong>右侧</strong>显示了当前登录的用户名<strong>“admin”</strong>和<strong>“退出”</strong>按钮，单击“退出”按钮即可退出后台系统。后台页面的<strong>左侧</strong>有一个菜单栏，用户可以在菜单栏中选择一个菜单项进行操作。项目中需要使用到的技术点包括<strong>文件上传</strong>、<strong>分页</strong>和<strong>会话技术</strong>。整个项目开发基于实现功能的步骤来完成，先实现后台开发，提供数据支持，再完成前台的数据展示。</p> 
<h3 id="%E5%AE%89%E8%A3%85Laravel"><a name="t1"></a>安装Laravel</h3> 
<p>首先选择你想在的哪个文件安装Laravel，然后就选择那个文件执行安装Larave命令：composer create-project --prefer-dist laravel/laravel ./ 5.8.*</p> 
<p>比如我想在D盘的&nbsp;<strong>phpstudy_pro-&gt;WWW&nbsp;</strong>里下载Laravel,则选择到D盘里的&nbsp;<strong>phpstudy_pro-&gt;WWW </strong>文件，然后在文件的上面写上<strong>cmd</strong>按下回车键，就可以进入到该文件的终端，然后执行安装Laravel的命令即可。操作如下图所示。</p> 
<p style="text-align:center;"><img alt="" src="https://img-blog.csdnimg.cn/544dda4bfa714d4e9831a07f978b3971.gif"></p> 
<p></p> 
<h3 id="%E9%85%8D%E7%BD%AE%E6%96%87%E4%BB%B6%C2%A0"><a name="t2"></a>配置文件&nbsp;</h3> 
<p>Laravel安装完成后，在Apache的<strong>conf\extra\httpd-vhosts.conf</strong>配置文件中创建一个虚拟主机。具体配置为：</p> 
<pre data-index="0" class="set-code-show" name="code"><code class="language-html hljs language-xml"><ol class="hljs-ln" style="width:100%"><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="1"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line"><span class="hljs-tag">&lt;<span class="hljs-name">VirtualHost</span> *<span class="hljs-attr">:80</span>&gt;</span></div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="2"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line">    DocumentRoot "C:/web/apache2.4/htdocs/cms/public"</div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="3"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line">    ServerName cms.com</div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="4"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line"><span class="hljs-tag">&lt;<span class="hljs-name">VirtualHost</span>&gt;</span></div></div></li></ol></code><div class="hljs-button {2}" data-title="复制" onclick="hljs.copyCode(event)"></div></pre> 
<p>然后，编辑Apache的<strong>hosts</strong>文件，添加一条解析记录“127.0.0.1 cms.com”。如下图所示。</p> 
<p style="text-align:center;"><img alt="" src="https://img-blog.csdnimg.cn/9724aedecafd45cfb1cb7f4e95cd025b.gif"></p> 
<p>&nbsp;登录MySQL服务器，创建数据库<strong>cms</strong>，将cms作为内容管理系统的数据库。</p> 
<p style="text-align:center;"><img alt="" src="https://img-blog.csdnimg.cn/c5161ad2af4747ac85bc48b7b2d1c7d0.png"></p> 
<p style="text-align:center;"><img alt="" src="https://img-blog.csdnimg.cn/1cd4e52e7e6f438782b12759ec477645.png"></p> 
<p>打开项目，在<strong>config\database.php</strong>数据库配置文件中，将数据库名称修改为<strong>cms</strong>。&nbsp;</p> 
<p style="text-align:center;"><img alt="" src="https://img-blog.csdnimg.cn/25f71df4e0c640db9628de34eaf17d5f.png"></p> 
<p>在<strong>.env</strong>文件中配置正确的数据库配置信息。全部完成后，即可在项目中访问数据库。&nbsp;</p> 
<p style="text-align:center;"><img alt="" src="https://img-blog.csdnimg.cn/358111e768f140ffa34935ebc2a68df8.png"></p> 
<h3 id="%E5%BC%95%E5%85%A5%E9%9C%80%E8%A6%81%E7%9A%84%E9%9D%99%E6%80%81%E6%96%87%E4%BB%B6"><a name="t3"></a>引入需要的静态文件</h3> 
<p></p> 
<h3 id="%E4%B8%80%E3%80%81%E5%90%8E%E5%8F%B0%E7%94%A8%E6%88%B7%E7%99%BB%E5%BD%95%C2%A0"><a name="t4"></a>一、后台用户登录&nbsp;</h3> 
<h4 id="1.%E5%88%9B%E5%BB%BA%E7%94%A8%E6%88%B7%E8%A1%A8"><a name="t5"></a>1.创建用户表</h4> 
<p>（1）在命令行中执行如下命令创建迁移文件，具体命令如下：</p> 
<pre data-index="1" class="set-code-show" name="code"><code class="language-php hljs">php artisan make:migration create_admin_user_table</code><div class="hljs-button {2}" data-title="复制" onclick="hljs.copyCode(event)"></div></pre> 
<p>（2）执行完上述命令后，会在<strong>database\migrations</strong>目录下生成文件名称为时间前缀<strong>_create_admin_user_table.php</strong>的文件&nbsp;。</p> 
<p>（3）在迁移文件的<strong>up()</strong>方法中添加表结构信息，具体代码如下：</p> 
<pre data-index="2" class="set-code-show" name="code"><code class="language-php hljs"><ol class="hljs-ln" style="width:100%"><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="1"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line"> <span class="hljs-keyword">public</span> <span class="hljs-function"><span class="hljs-keyword">function</span> <span class="hljs-title">up</span>(<span class="hljs-params"></span>)</span></div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="2"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line">    {</div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="3"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line">        <span class="hljs-title class_">Schema</span>::<span class="hljs-title function_ invoke__">create</span>(<span class="hljs-string">'admin_user'</span>, function (Blueprint <span class="hljs-variable">$table</span>) {</div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="4"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line">            <span class="hljs-variable">$table</span>-&gt;<span class="hljs-title function_ invoke__">increments</span>(<span class="hljs-string">'id'</span>)-&gt;<span class="hljs-title function_ invoke__">comment</span>(<span class="hljs-string">'主键'</span>);</div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="5"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line">            <span class="hljs-variable">$table</span>-&gt;<span class="hljs-keyword">string</span>(<span class="hljs-string">'username'</span>, <span class="hljs-number">32</span>)-&gt;<span class="hljs-title function_ invoke__">comment</span>(<span class="hljs-string">'用户名'</span>)-&gt;<span class="hljs-title function_ invoke__">unique</span>();</div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="6"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line">            <span class="hljs-variable">$table</span>-&gt;<span class="hljs-keyword">string</span>(<span class="hljs-string">'password'</span>, <span class="hljs-number">32</span>)-&gt;<span class="hljs-title function_ invoke__">comment</span>(<span class="hljs-string">'密码'</span>);</div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="7"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line">            <span class="hljs-variable">$table</span>-&gt;<span class="hljs-title function_ invoke__">char</span>(<span class="hljs-string">'salt'</span>, <span class="hljs-number">32</span>)-&gt;<span class="hljs-title function_ invoke__">comment</span>(<span class="hljs-string">'密码salt'</span>);</div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="8"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line">            <span class="hljs-variable">$table</span>-&gt;<span class="hljs-title function_ invoke__">timestamps</span>();</div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="9"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line"> </div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="10"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line">        });</div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="11"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line">    }</div></div></li></ol></code><div class="hljs-button {2}" data-title="复制" onclick="hljs.copyCode(event)"></div></pre> 
<p>（4）迁移文件创建完成后，使用如下命令来执行迁移</p> 
<pre data-index="3" class="set-code-show" name="code"><code class="language-php hljs">php artisan migrate</code><div class="hljs-button {2}" data-title="复制" onclick="hljs.copyCode(event)"></div></pre> 
<p>（5）上述命令会执行迁移文件中的<strong>up()</strong>方法，来完成数据表的创建。</p> 
<p>（6）创建填充文件，具体命令如下：</p> 
<pre data-index="4" class="set-code-show" name="code"><code class="language-php hljs">php artisan make:seeder AdminuserTableSeeder
</code><div class="hljs-button {2}" data-title="复制" onclick="hljs.copyCode(event)"></div></pre> 
<p style="margin-left:0in;text-align:justify;"><span style="color:#595959;">（7）执行完上述命令后，会在</span><strong><span style="color:#595959;">database\seeds</span></strong><span style="color:#595959;">目录下生成对应的迁移文件，文件名为</span><span style="color:#1369b2;">AdminuserTableSeeder.php。</span></p> 
<p style="margin-left:0in;text-align:justify;"><span style="color:#595959;">（8）在填充文件的</span><span style="color:#595959;">run()</span><span style="color:#595959;">方法中编写填充代码：</span></p> 
<pre data-index="5" class="set-code-show" name="code"><code class="language-php hljs"><ol class="hljs-ln" style="width:100%"><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="1"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line"><span class="hljs-keyword">public</span> <span class="hljs-function"><span class="hljs-keyword">function</span> <span class="hljs-title">run</span>(<span class="hljs-params"></span>)</span></div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="2"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line">{</div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="3"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line">    <span class="hljs-variable">$salt</span> = <span class="hljs-title function_ invoke__">md5</span>(<span class="hljs-title function_ invoke__">uniqid</span>(<span class="hljs-title function_ invoke__">microtime</span>(), <span class="hljs-literal">true</span>));</div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="4"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line">    <span class="hljs-variable">$password</span> = <span class="hljs-title function_ invoke__">md5</span>(<span class="hljs-title function_ invoke__">md5</span>(<span class="hljs-string">'123456'</span>) . <span class="hljs-variable">$salt</span>);</div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="5"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line">    DB::<span class="hljs-title function_ invoke__">table</span>(<span class="hljs-string">'admin_user'</span>)-&gt;<span class="hljs-title function_ invoke__">insert</span>([</div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="6"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line">        [</div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="7"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line">            <span class="hljs-string">'id'</span> =&gt; <span class="hljs-number">1</span>,</div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="8"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line">            <span class="hljs-string">'username'</span> =&gt; <span class="hljs-string">'admin'</span>,</div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="9"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line">            <span class="hljs-string">'password'</span> =&gt; <span class="hljs-variable">$password</span>,</div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="10"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line">            <span class="hljs-string">'salt'</span> =&gt; <span class="hljs-variable">$salt</span></div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="11"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line">        ],</div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="12"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line">    ]);</div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="13"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line">}</div></div></li></ol></code><div class="hljs-button {2}" data-title="复制" onclick="hljs.copyCode(event)"></div></pre> 
<p style="margin-left:0in;text-align:justify;"><span style="color:#595959;">（9）执行填充文件命令：</span></p> 
<pre data-index="6" class="set-code-show" name="code"><code class="language-php hljs"><ol class="hljs-ln" style="width:100%"><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="1"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line">php artisan db:seed --<span class="hljs-class"><span class="hljs-keyword">class</span>=<span class="hljs-title">AdminuserTableSeeder</span></span></div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="2"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line"></div></div></li></ol></code><div class="hljs-button {2}" data-title="复制" onclick="hljs.copyCode(event)"></div></pre> 
<p style="margin-left:0in;text-align:justify;"><span style="color:#595959;">（10）数据库创建成功后，创建用户模型：</span></p> 
<pre data-index="7" class="set-code-show" name="code"><code class="language-php hljs">php artisan make:model Admin
</code><div class="hljs-button {2}" data-title="复制" onclick="hljs.copyCode(event)"></div></pre> 
<p>（11）打开<strong>app\Admin.php</strong>,在模型中指定要操作的表名，具体代码如下：</p> 
<pre data-index="8" class="set-code-show" name="code"><code class="language-php hljs"><ol class="hljs-ln" style="width:100%"><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="1"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line"><span class="hljs-meta">&lt;?php</span></div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="2"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line"> </div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="3"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line"><span class="hljs-keyword">namespace</span> <span class="hljs-title class_">App</span>;</div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="4"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line"> </div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="5"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line"><span class="hljs-keyword">use</span> <span class="hljs-title">Illuminate</span>\<span class="hljs-title">Database</span>\<span class="hljs-title">Eloquent</span>\<span class="hljs-title">Model</span>;</div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="6"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line"> </div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="7"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line"><span class="hljs-class"><span class="hljs-keyword">class</span> <span class="hljs-title">Admin</span> <span class="hljs-keyword">extends</span> <span class="hljs-title">Model</span></span></div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="8"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line">{</div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="9"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line">    <span class="hljs-keyword">protected</span> <span class="hljs-variable">$table</span> = <span class="hljs-string">'admin_user'</span>;</div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="10"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line">    <span class="hljs-keyword">public</span> <span class="hljs-variable">$fillable</span> = [<span class="hljs-string">'username'</span>, <span class="hljs-string">'password'</span>];</div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="11"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line">}</div></div></li></ol></code><div class="hljs-button {2}" data-title="复制" onclick="hljs.copyCode(event)"></div></pre> 
<h4 id="2.%E6%98%BE%E7%A4%BA%E7%99%BB%E5%BD%95%E9%A1%B5%E9%9D%A2"><a name="t6"></a>2.显示登录页面</h4> 
<p>（1）创建User控制器,具体代码如下：</p> 
<pre data-index="9" class="set-code-show" name="code"><code class="language-php hljs">php artisan make:controller Admin/UserController</code><div class="hljs-button {2}" data-title="复制" onclick="hljs.copyCode(event)"></div></pre> 
<p>（2）执行完上述命令后，会在<strong>app\Http\Controllers\Admin</strong>目录下创建<strong>UserController.php</strong>,命名空间为<strong>App\Http\Controllers\Admin</strong>。</p> 
<p>（3）打开<strong>UserController.php</strong>,创建<strong>login()</strong>方法,具体代码如下：</p> 
<pre data-index="10" class="set-code-show" name="code"><code class="language-php hljs"><ol class="hljs-ln" style="width:100%"><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="1"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line"><span class="hljs-keyword">public</span> <span class="hljs-function"><span class="hljs-keyword">function</span> <span class="hljs-title">login</span>(<span class="hljs-params"></span>)</span>{</div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="2"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line">    <span class="hljs-keyword">return</span> <span class="hljs-title function_ invoke__">view</span>(<span class="hljs-string">'admin/login'</span>);</div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="3"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line">}</div></div></li></ol></code><div class="hljs-button {2}" data-title="复制" onclick="hljs.copyCode(event)"></div></pre> 
<p>（4）在routes\web.php文件中添加路由规则，具体代码如下：</p> 
<pre data-index="11" class="set-code-show" name="code"><code class="language-php hljs"><span class="hljs-title class_">Route</span>::<span class="hljs-title function_ invoke__">get</span>(<span class="hljs-string">'/admin/login'</span>,<span class="hljs-string">'Admin\UserController@login'</span>);</code><div class="hljs-button {2}" data-title="复制" onclick="hljs.copyCode(event)"></div></pre> 
<p>（5）在resources\views目录下创建admin目录,该目录用于存放后台相关的模板文件。在admin目录中创建login.blade.php文件，具体代码如下：</p> 
<pre data-index="12" class="set-code-show" name="code"><code class="language-php hljs"><ol class="hljs-ln" style="width:100%"><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="1"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line">&lt;!DOCTYPE html&gt;</div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="2"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line">&lt;html lang=<span class="hljs-string">"en"</span>&gt;</div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="3"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line">&lt;head&gt;</div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="4"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line">    &lt;meta charset=<span class="hljs-string">"UTF-8"</span>&gt;</div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="5"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line">    &lt;meta name=<span class="hljs-string">"viewport"</span> content=<span class="hljs-string">"width=device-width, initial-scale=1.0"</span>&gt;</div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="6"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line">    &lt;!-- 引入静态文件 --&gt;</div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="7"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line">    &lt;title&gt;登录&lt;/title&gt;</div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="8"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line">&lt;/head&gt;</div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="9"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line">&lt;body <span class="hljs-class"><span class="hljs-class"><span class="hljs-keyword">class</span>="<span class="hljs-title">login</span>"&gt;</span></span></div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="10"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line"><span class="hljs-class">&lt;<span class="hljs-title">div</span> <span class="hljs-title">class</span>="<span class="hljs-title">container</span>"&gt;</span></div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="11"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line"><span class="hljs-class">&lt;!-- 登录表单 --&gt;</span></div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="12"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line"><span class="hljs-class">&lt;/<span class="hljs-title">div</span>&gt;</span></div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="13"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line"><span class="hljs-class">&lt;/<span class="hljs-title">body</span>&gt;</span></div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="14"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line"><span class="hljs-class">&lt;/<span class="hljs-title">html</span>&gt;</span></div></div></li></ol></code><div class="hljs-button {2}" data-title="复制" onclick="hljs.copyCode(event)"></div></pre> 
<p>（6）在上述的第6行引入静态文件，具体代码如下：</p> 
<pre data-index="13" class="set-code-show" name="code"><code class="language-html hljs language-xml"><ol class="hljs-ln" style="width:100%"><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="1"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line">    <span class="hljs-tag">&lt;<span class="hljs-name">link</span> <span class="hljs-attr">rel</span>=<span class="hljs-string">"stylesheet"</span> <span class="hljs-attr">href</span>=<span class="hljs-string">"{{asset('admin')}}/common/twitter-bootstrap/4.4.1/css/bootstrap.min.css"</span>&gt;</span></div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="2"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line">    <span class="hljs-tag">&lt;<span class="hljs-name">link</span> <span class="hljs-attr">rel</span>=<span class="hljs-string">"stylesheet"</span> <span class="hljs-attr">href</span>=<span class="hljs-string">"{{asset('admin')}}/common/font-awesome-4.2.0/css/font-awesome.min.css"</span>&gt;</span></div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="3"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line">    <span class="hljs-tag">&lt;<span class="hljs-name">link</span> <span class="hljs-attr">rel</span>=<span class="hljs-string">"stylesheet"</span> <span class="hljs-attr">href</span>=<span class="hljs-string">"{{asset('admin')}}/common/toastr.js/2.1.4/toastr.min.css"</span>&gt;</span></div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="4"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line">    <span class="hljs-tag">&lt;<span class="hljs-name">link</span> <span class="hljs-attr">rel</span>=<span class="hljs-string">"stylesheet"</span> <span class="hljs-attr">href</span>=<span class="hljs-string">"{{asset('admin')}}/css/main.css"</span>&gt;</span></div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="5"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line">    <span class="hljs-tag">&lt;<span class="hljs-name">script</span> <span class="hljs-attr">src</span>=<span class="hljs-string">"{{asset('admin')}}/common/jquery/1.12.4/jquery.min.js"</span>&gt;</span><span class="hljs-tag">&lt;/<span class="hljs-name">script</span>&gt;</span></div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="6"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line">    <span class="hljs-tag">&lt;<span class="hljs-name">script</span> <span class="hljs-attr">src</span>=<span class="hljs-string">"{{asset('admin')}}/common/twitter-bootstrap/4.4.1/js/bootstrap.min.js"</span>&gt;</span><span class="hljs-tag">&lt;/<span class="hljs-name">script</span>&gt;</span></div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="7"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line">    <span class="hljs-tag">&lt;<span class="hljs-name">script</span> <span class="hljs-attr">src</span>=<span class="hljs-string">"{{asset('admin')}}/common/toastr.js/2.1.4/toastr.min.js"</span>&gt;</span><span class="hljs-tag">&lt;/<span class="hljs-name">script</span>&gt;</span></div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="8"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line">    <span class="hljs-tag">&lt;<span class="hljs-name">script</span> <span class="hljs-attr">src</span>=<span class="hljs-string">"{{asset('admin')}}/js/main.js"</span>&gt;</span><span class="hljs-tag">&lt;/<span class="hljs-name">script</span>&gt;</span></div></div></li></ol></code><div class="hljs-button {2}" data-title="复制" onclick="hljs.copyCode(event)"></div></pre> 
<p>&nbsp;（7）在注释登录表单下面定义登录表单，具体代码如下：</p> 
<pre data-index="14" class="set-code-show" name="code"><code class="language-html hljs language-xml"><ol class="hljs-ln" style="width:100%"><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="1"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line"><span class="hljs-tag">&lt;<span class="hljs-name">form</span> <span class="hljs-attr">action</span>=<span class="hljs-string">""</span> <span class="hljs-attr">method</span>=<span class="hljs-string">"post"</span> <span class="hljs-attr">class</span>=<span class="hljs-string">"j-login"</span>&gt;</span></div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="2"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line">    <span class="hljs-tag">&lt;<span class="hljs-name">h1</span>&gt;</span>后台管理系统<span class="hljs-tag">&lt;/<span class="hljs-name">h1</span>&gt;</span></div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="3"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line">    <span class="hljs-tag">&lt;<span class="hljs-name">div</span> <span class="hljs-attr">class</span>=<span class="hljs-string">"form-group"</span>&gt;</span></div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="4"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line">      <span class="hljs-tag">&lt;<span class="hljs-name">input</span> <span class="hljs-attr">type</span>=<span class="hljs-string">"text"</span> <span class="hljs-attr">name</span>=<span class="hljs-string">"username"</span> <span class="hljs-attr">class</span>=<span class="hljs-string">"form-control"</span> <span class="hljs-attr">placeholder</span>=<span class="hljs-string">"用户名"</span> <span class="hljs-attr">required</span>&gt;</span></div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="5"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line">    <span class="hljs-tag">&lt;/<span class="hljs-name">div</span>&gt;</span></div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="6"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line">    <span class="hljs-tag">&lt;<span class="hljs-name">div</span> <span class="hljs-attr">class</span>=<span class="hljs-string">"form-group"</span>&gt;</span></div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="7"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line">      <span class="hljs-tag">&lt;<span class="hljs-name">input</span> <span class="hljs-attr">type</span>=<span class="hljs-string">"password"</span> <span class="hljs-attr">name</span>=<span class="hljs-string">"password"</span> <span class="hljs-attr">class</span>=<span class="hljs-string">"form-control"</span> <span class="hljs-attr">placeholder</span>=<span class="hljs-string">"密码"</span> <span class="hljs-attr">required</span>&gt;</span></div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="8"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line">    <span class="hljs-tag">&lt;/<span class="hljs-name">div</span>&gt;</span></div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="9"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line">    <span class="hljs-tag">&lt;<span class="hljs-name">div</span> <span class="hljs-attr">class</span>=<span class="hljs-string">"form-group"</span>&gt;</span></div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="10"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line">      <span class="hljs-tag">&lt;<span class="hljs-name">input</span> <span class="hljs-attr">type</span>=<span class="hljs-string">"text"</span> <span class="hljs-attr">name</span>=<span class="hljs-string">"captcha"</span> <span class="hljs-attr">class</span>=<span class="hljs-string">"form-control"</span> <span class="hljs-attr">placeholder</span>=<span class="hljs-string">"验证码"</span> <span class="hljs-attr">required</span>&gt;</span></div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="11"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line">    <span class="hljs-tag">&lt;/<span class="hljs-name">div</span>&gt;</span></div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="12"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line">    <span class="hljs-comment">&lt;!-- 验证码 --&gt;</span></div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="13"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line">    <span class="hljs-tag">&lt;<span class="hljs-name">div</span> <span class="hljs-attr">class</span>=<span class="hljs-string">"form-group"</span>&gt;</span></div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="14"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line">      {{csrf_field()}}</div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="15"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line">      <span class="hljs-tag">&lt;<span class="hljs-name">input</span> <span class="hljs-attr">type</span>=<span class="hljs-string">"submit"</span> <span class="hljs-attr">class</span>=<span class="hljs-string">"btn btn-lg btn-block btn-success"</span> <span class="hljs-attr">value</span>=<span class="hljs-string">"登录"</span>&gt;</span></div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="16"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line">    <span class="hljs-tag">&lt;/<span class="hljs-name">div</span>&gt;</span></div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="17"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line"><span class="hljs-tag">&lt;/<span class="hljs-name">form</span>&gt;</span></div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="18"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line"> </div></div></li></ol></code><div class="hljs-button {2}" data-title="复制" onclick="hljs.copyCode(event)"></div></pre> 
<p>（8）使用Composer载入mews/captcha验证码库，具体代码如下：</p> 
<pre data-index="15" class="set-code-show" name="code"><code class="language-php hljs">composer <span class="hljs-keyword">require</span> mews/captcha=<span class="hljs-number">3.0</span></code><div class="hljs-button {2}" data-title="复制" onclick="hljs.copyCode(event)"></div></pre> 
<p>（9）创建验证码的配置文件 ,具体命令如下：</p> 
<pre data-index="16" class="set-code-show" name="code"><code class="language-php hljs">php artisan vendor:publish</code><div class="hljs-button {2}" data-title="复制" onclick="hljs.copyCode(event)"></div></pre> 
<p>（10）执行完上述命令后，在命令行中输入序号<strong>“9”</strong>并按<strong>"Enter"</strong>键，就会自动生成<strong>config\captcha.php</strong>文件。</p> 
<p>（11）编辑<strong>config\captcha.php文件，</strong>将字符个数改为4，具体代码如下：</p> 
<pre data-index="17" class="set-code-show" name="code"><code class="language-php hljs"><ol class="hljs-ln" style="width:100%"><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="1"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line"><span class="hljs-string">'default'</span> =&gt; [</div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="2"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line">        <span class="hljs-string">'length'</span> =&gt; <span class="hljs-number">4</span>, <span class="hljs-comment">//字符个数</span></div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="3"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line">        <span class="hljs-string">'width'</span> =&gt; <span class="hljs-number">120</span>, <span class="hljs-comment">//图片宽度</span></div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="4"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line">        <span class="hljs-string">'height'</span> =&gt; <span class="hljs-number">36</span>, <span class="hljs-comment">//图片高度</span></div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="5"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line">        <span class="hljs-string">'quality'</span> =&gt; <span class="hljs-number">90</span>, <span class="hljs-comment">//图片质量</span></div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="6"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line">        <span class="hljs-string">'math'</span> =&gt; <span class="hljs-literal">false</span>, <span class="hljs-comment">//数学计算</span></div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="7"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line">    ],</div></div></li></ol></code><div class="hljs-button {2}" data-title="复制" onclick="hljs.copyCode(event)"></div></pre> 
<p>（12）在<strong>config\app.php</strong>中将验证码服务注册到服务器中，具体代码如下：</p> 
<pre data-index="18" class="set-code-show" name="code"><code class="language-php hljs"><ol class="hljs-ln" style="width:100%"><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="1"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line"><span class="hljs-string">'providers'</span> =&gt; [</div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="2"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line">     ...(原有代码)</div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="3"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line">     <span class="hljs-title class_">Mews\Captcha\CaptchaServiceProvider</span>::<span class="hljs-variable language_">class</span>,</div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="4"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line">     ...(原有代码)</div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="5"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line">]</div></div></li></ol></code><div class="hljs-button {2}" data-title="复制" onclick="hljs.copyCode(event)"></div></pre> 
<p>（13）在<strong>config\app.php</strong>文件中给验证码服务注册别名，具体代码如下：</p> 
<pre data-index="19" class="set-code-show" name="code"><code class="language-php hljs"><ol class="hljs-ln" style="width:100%"><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="1"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line"><span class="hljs-string">'aliases'</span> =&gt; [</div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="2"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line">     ...(原有代码)</div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="3"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line">    <span class="hljs-string">'Captcha'</span> =&gt;<span class="hljs-title class_">Mews\Captcha\Facades\Captcha</span>::<span class="hljs-variable language_">class</span>,</div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="4"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line">]</div></div></li></ol></code><div class="hljs-button {2}" data-title="复制" onclick="hljs.copyCode(event)"></div></pre> 
<p>（14)在登录表单中添加验证码,具体代码如下：</p> 
<pre data-index="20" class="set-code-show" name="code"><code class="language-php hljs"><ol class="hljs-ln" style="width:100%"><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="1"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line">&lt;div <span class="hljs-class"><span class="hljs-class"><span class="hljs-keyword">class</span>="<span class="hljs-title">form</span>-<span class="hljs-title">group</span>"&gt;</span></span></div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="2"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line"><span class="hljs-class">      &lt;<span class="hljs-title">div</span> <span class="hljs-title">class</span>="<span class="hljs-title">login</span>-<span class="hljs-title">captcha</span>"&gt;&lt;<span class="hljs-title">img</span> <span class="hljs-title">src</span>="</span>{{ <span class="hljs-title function_ invoke__">captcha_src</span>() }}<span class="hljs-string">" alt="</span>captcha<span class="hljs-string"><span class="hljs-string">"&gt;&lt;/div&gt;</span></span></div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="3"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line"><span class="hljs-string"> &lt;/div&gt;</span></div></div></li></ol></code><div class="hljs-button {2}" data-title="复制" onclick="hljs.copyCode(event)"></div></pre> 
<p>(15)通过浏览器访问，其页面效果如下图：</p> 
<p><img alt="" height="651" src="https://img-blog.csdnimg.cn/431d85ef3e1c4cedb675ea26d4a3f3e3.png" width="1200"></p> 
<p>（16）实现单机验证码图片后更换验证码功能，在模板中编写JavaScript代码，具体代码如下：</p> 
<pre data-index="21" class="set-code-show" name="code"><code class="language-php hljs"><ol class="hljs-ln" style="width:100%"><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="1"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line"> &lt;script&gt;</div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="2"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line">    $(<span class="hljs-string">'.login-captcha img'</span>).<span class="hljs-title function_ invoke__">click</span>(function() {</div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="3"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line">    $(this).<span class="hljs-title function_ invoke__">attr</span>(<span class="hljs-string">'src'</span>, <span class="hljs-string">'{{ captcha_src()}}'</span> + <span class="hljs-string">'?_='</span> + Math.<span class="hljs-title function_ invoke__">random</span>());</div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="4"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line">  });</div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="5"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line">&lt;/script&gt; </div></div></li></ol></code><div class="hljs-button {2}" data-title="复制" onclick="hljs.copyCode(event)"></div></pre> 
<h4 id="3.Ajax%E4%BA%A4%E4%BA%92"><a name="t7"></a>3.Ajax交互</h4> 
<p>（1）打开<strong>public\admin\js\main.js</strong>文件，添加如下代码：</p> 
<pre data-index="22" class="set-code-show" name="code"><code class="language-php hljs"><ol class="hljs-ln" style="width:100%"><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="1"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line">(<span class="hljs-function"><span class="hljs-keyword">function</span> (<span class="hljs-params">window, $, toastr</span>) </span>{</div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="2"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line">  window.main = {</div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="3"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line">    token: <span class="hljs-string">''</span>,					<span class="hljs-comment">// 保存令牌</span></div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="4"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line">    toastr: toastr,</div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="5"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line">    init: <span class="hljs-function"><span class="hljs-keyword">function</span> (<span class="hljs-params">opt</span>) </span>{</div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="6"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line">      $.<span class="hljs-title function_ invoke__">extend</span>(this, opt);		<span class="hljs-comment">// 将传入的opt对象合并到自身对象中</span></div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="7"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line">      toastr.options.positionClass = <span class="hljs-string">'toast-top-center'</span>;</div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="8"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line">      <span class="hljs-keyword">return</span> this;</div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="9"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line">    },</div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="10"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line">    ajax: <span class="hljs-function"><span class="hljs-keyword">function</span> (<span class="hljs-params">opt, success, error</span>) </span>{</div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="11"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line">      opt = (typeof opt === <span class="hljs-string">'string'</span>) ? {url: opt} : opt;</div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="12"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line">      <span class="hljs-keyword">var</span> that = this;</div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="13"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line">      <span class="hljs-keyword">var</span> options = {</div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="14"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line">        success: <span class="hljs-function"><span class="hljs-keyword">function</span> (<span class="hljs-params">data, status, xhr</span>) </span>{</div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="15"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line">          that.<span class="hljs-title function_ invoke__">hideLoading</span>();</div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="16"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line">          <span class="hljs-keyword">if</span> (!data) {</div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="17"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line">            toastr.<span class="hljs-title function_ invoke__">error</span>(<span class="hljs-string">'请求失败，请重试。'</span>);</div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="18"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line">          } <span class="hljs-keyword">else</span> <span class="hljs-keyword">if</span> (data.code === <span class="hljs-number">0</span>) {</div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="19"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line">            toastr.<span class="hljs-title function_ invoke__">error</span>(data.msg);</div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="20"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line">            error &amp;&amp; <span class="hljs-title function_ invoke__">error</span>(data);</div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="21"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line">          } <span class="hljs-keyword">else</span> {</div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="22"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line">            success &amp;&amp; <span class="hljs-title function_ invoke__">success</span>(data);</div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="23"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line">          }</div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="24"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line">          opt.success &amp;&amp; opt.<span class="hljs-title function_ invoke__">success</span>(data, status, xhr);</div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="25"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line">        },</div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="26"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line">        error: <span class="hljs-function"><span class="hljs-keyword">function</span> (<span class="hljs-params">xhr, status, err</span>) </span>{</div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="27"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line">          that.<span class="hljs-title function_ invoke__">hideLoading</span>();</div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="28"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line">          toastr.<span class="hljs-title function_ invoke__">error</span>(<span class="hljs-string">'请求失败，请重试。'</span>);</div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="29"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line">          opt.error &amp;&amp; opt.<span class="hljs-title function_ invoke__">error</span>(xhr, status, err);</div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="30"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line">        }</div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="31"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line">      };</div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="32"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line">      that.<span class="hljs-title function_ invoke__">showLoading</span>();</div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="33"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line">      $.<span class="hljs-title function_ invoke__">ajax</span>($.<span class="hljs-title function_ invoke__">extend</span>({}, opt, options));</div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="34"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line">    },</div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="35"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line">    showLoading: <span class="hljs-function"><span class="hljs-keyword">function</span>(<span class="hljs-params"></span>) </span>{</div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="36"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line">      $(<span class="hljs-string">'.main-loading'</span>).<span class="hljs-title function_ invoke__">show</span>();</div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="37"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line">    },</div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="38"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line">    hideLoading: <span class="hljs-function"><span class="hljs-keyword">function</span>(<span class="hljs-params"></span>) </span>{</div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="39"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line">      $(<span class="hljs-string">'.main-loading'</span>).<span class="hljs-title function_ invoke__">hide</span>();</div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="40"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line">    },</div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="41"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line">  };</div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="42"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line">})(this, jQuery, toastr);</div></div></li></ol></code><div class="hljs-button {2}" data-title="复制" onclick="hljs.copyCode(event)"></div></pre> 
<p>（2）在main对象中编写<strong>ajaxPost()</strong>方法，具体代码如下：</p> 
<pre data-index="23" class="set-code-show" name="code"><code class="language-php hljs"><ol class="hljs-ln" style="width:100%"><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="1"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line">ajaxPost: <span class="hljs-function"><span class="hljs-keyword">function</span>(<span class="hljs-params">opt, success, error</span>) </span>{</div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="2"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line">      opt = (typeof opt === <span class="hljs-string">'string'</span>) ? {url: opt} : opt;</div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="3"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line">      <span class="hljs-keyword">var</span> that = this;</div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="4"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line">      <span class="hljs-keyword">var</span> callback = opt.success;</div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="5"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line">      opt.type = <span class="hljs-string">'POST'</span>;</div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="6"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line">      opt.success = <span class="hljs-function"><span class="hljs-keyword">function</span>(<span class="hljs-params">data, status, xhr</span>) </span>{</div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="7"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line">        <span class="hljs-keyword">if</span> (data &amp;&amp; data.code === <span class="hljs-number">1</span>) {</div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="8"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line">          toastr.<span class="hljs-title function_ invoke__">success</span>(data.msg);</div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="9"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line">        }</div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="10"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line">        callback &amp;&amp; <span class="hljs-title function_ invoke__">callback</span>(data, status, xhr);</div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="11"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line">      };</div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="12"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line">      that.<span class="hljs-title function_ invoke__">ajax</span>(opt, success, error);</div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="13"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line">    },</div></div></li></ol></code><div class="hljs-button {2}" data-title="复制" onclick="hljs.copyCode(event)"></div></pre> 
<p>（3）在<strong>main.js中</strong>编写<strong>ajaxForm()</strong>方法，用于将表单改为Ajax提交方式，具体代码如下：</p> 
<pre data-index="24" class="set-code-show" name="code"><code class="language-php hljs"><ol class="hljs-ln" style="width:100%"><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="1"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line"> ajaxForm: <span class="hljs-function"><span class="hljs-keyword">function</span> (<span class="hljs-params">selector, success, error</span>) </span>{</div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="2"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line">      <span class="hljs-keyword">var</span> form = $(selector);</div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="3"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line">      <span class="hljs-keyword">var</span> that = this;</div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="4"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line">      form.<span class="hljs-title function_ invoke__">submit</span>(function (e) {</div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="5"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line">        e.<span class="hljs-title function_ invoke__">preventDefault</span>();</div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="6"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line">        that.<span class="hljs-title function_ invoke__">ajaxPost</span>({</div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="7"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line">          <span class="hljs-attr">url</span>: form.<span class="hljs-title function_ invoke__">attr</span>(<span class="hljs-string">'action'</span>),</div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="8"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line">          <span class="hljs-attr">data</span>: <span class="hljs-keyword">new</span> <span class="hljs-title class_">FormData</span>(form.<span class="hljs-title function_ invoke__">get</span>(<span class="hljs-number">0</span>)),</div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="9"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line">          contentType: <span class="hljs-literal">false</span>,</div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="10"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line">          processData: <span class="hljs-literal">false</span></div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="11"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line">        }, success, error);</div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="12"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line">      });</div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="13"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line">    },</div></div></li></ol></code><div class="hljs-button {2}" data-title="复制" onclick="hljs.copyCode(event)"></div></pre> 
<h4 id="4.%E9%AA%8C%E8%AF%81%E7%94%A8%E6%88%B7%E7%99%BB%E5%BD%95"><a name="t8"></a>4.验证用户登录</h4> 
<p>（1）在<strong>routes\web.php</strong>文件中添加路由规则，具体代码如下：</p> 
<pre data-index="25" class="set-code-show" name="code"><code class="language-php hljs"><ol class="hljs-ln" style="width:100%"><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="1"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line"><span class="hljs-comment">//登录验证</span></div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="2"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line"><span class="hljs-title class_">Route</span>::<span class="hljs-title function_ invoke__">post</span>(<span class="hljs-string">'/admin/check'</span>,<span class="hljs-string">'Admin\UserController@check'</span>);</div></div></li></ol></code><div class="hljs-button {2}" data-title="复制" onclick="hljs.copyCode(event)"></div></pre> 
<p>（2）在<strong>UserController.php</strong>中创建<strong>check()</strong>方法，具体代码如下：</p> 
<pre data-index="26" class="set-code-show" name="code"><code class="language-php hljs"><ol class="hljs-ln" style="width:100%"><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="1"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line"><span class="hljs-keyword">public</span> <span class="hljs-function"><span class="hljs-keyword">function</span> <span class="hljs-title">check</span>(<span class="hljs-params">Request <span class="hljs-variable">$request</span></span>)</span></div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="2"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line">    {</div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="3"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line">        <span class="hljs-comment">//声明自动验证规则</span></div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="4"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line">        <span class="hljs-variable">$rule</span> = [</div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="5"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line">            <span class="hljs-string">'username'</span> =&gt; <span class="hljs-string">'required'</span>,</div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="6"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line">            <span class="hljs-string">'password'</span> =&gt; <span class="hljs-string">'required|min:6'</span>,</div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="7"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line">            <span class="hljs-string">'captcha'</span> =&gt; <span class="hljs-string">'required|captcha'</span></div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="8"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line">        ];</div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="9"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line">        <span class="hljs-comment">// 声明自动验证规则对应的提示信息（验证失败返回信息）</span></div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="10"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line">        <span class="hljs-variable">$message</span> = [</div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="11"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line">            <span class="hljs-string">'username.required'</span> =&gt; <span class="hljs-string">'用户名不能为空'</span>,</div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="12"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line">            <span class="hljs-string">'password.required'</span> =&gt; <span class="hljs-string">'密码不能为空'</span>,</div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="13"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line">            <span class="hljs-string">'password.min'</span>     =&gt; <span class="hljs-string">'密码最少为6位'</span>,</div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="14"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line">            <span class="hljs-string">'captcha.required'</span> =&gt; <span class="hljs-string">'验证码不能为空'</span>,</div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="15"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line">            <span class="hljs-string">'captcha.captcha'</span> =&gt; <span class="hljs-string">'验证码有误'</span></div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="16"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line">        ];</div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="17"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line">        <span class="hljs-comment">//进行自动验证，验证表单提交数据</span></div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="18"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line">        <span class="hljs-variable">$validator</span> = <span class="hljs-title class_">Validator</span>::<span class="hljs-title function_ invoke__">make</span>(<span class="hljs-variable">$request</span>-&gt;<span class="hljs-title function_ invoke__">all</span>(), <span class="hljs-variable">$rule</span>, <span class="hljs-variable">$message</span>);</div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="19"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line">        <span class="hljs-comment">// 输出验证结果并返回给浏览器</span></div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="20"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line">        <span class="hljs-keyword">if</span> (<span class="hljs-variable">$validator</span>-&gt;<span class="hljs-title function_ invoke__">fails</span>()) {   <span class="hljs-comment">//验证失败fails()方法</span></div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="21"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line">            <span class="hljs-keyword">foreach</span> (<span class="hljs-variable">$validator</span>-&gt;<span class="hljs-title function_ invoke__">getMessageBag</span>()-&gt;<span class="hljs-title function_ invoke__">toArray</span>() <span class="hljs-keyword">as</span> <span class="hljs-variable">$v</span>) {</div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="22"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line">                <span class="hljs-variable">$msg</span> = <span class="hljs-variable">$v</span>[<span class="hljs-number">0</span>];</div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="23"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line">            }</div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="24"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line">            <span class="hljs-keyword">return</span> <span class="hljs-title function_ invoke__">response</span>()-&gt;<span class="hljs-title function_ invoke__">json</span>([<span class="hljs-string">'code'</span> =&gt; <span class="hljs-number">0</span>, <span class="hljs-string">'msg'</span> =&gt; <span class="hljs-variable">$msg</span>]);</div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="25"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line">        }</div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="26"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line">        <span class="hljs-comment">// 获取用户输入的用户名、密码信息，以及数据表中用户名、密码信息</span></div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="27"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line">        <span class="hljs-variable">$username</span> = <span class="hljs-variable">$request</span>-&gt;<span class="hljs-title function_ invoke__">get</span>(<span class="hljs-string">'username'</span>);</div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="28"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line">        <span class="hljs-variable">$password</span> = <span class="hljs-variable">$request</span>-&gt;<span class="hljs-title function_ invoke__">get</span>(<span class="hljs-string">'password'</span>);</div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="29"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line">        <span class="hljs-variable">$theUser</span> = <span class="hljs-title class_">Admin</span>::<span class="hljs-title function_ invoke__">where</span>(<span class="hljs-string">'username'</span>,<span class="hljs-variable">$username</span>)-&gt;<span class="hljs-title function_ invoke__">first</span>();</div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="30"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line">        <span class="hljs-comment">// 对用户输入的密码与数据库中的密码进行比较，如果密码正确则登录成功，并将用户信息保存在session中</span></div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="31"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line">        <span class="hljs-comment">// 跳转至后台首页，如果登录失败，则显示“登录失败”</span></div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="32"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line">        <span class="hljs-keyword">if</span>(<span class="hljs-variable">$theUser</span>-&gt;password == <span class="hljs-title function_ invoke__">md5</span>(<span class="hljs-title function_ invoke__">md5</span>(<span class="hljs-variable">$password</span>). <span class="hljs-variable">$theUser</span>-&gt;salt))</div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="33"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line">        {</div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="34"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line">            <span class="hljs-title class_">Session</span>::<span class="hljs-title function_ invoke__">put</span>(<span class="hljs-string">'user'</span>, [<span class="hljs-string">'id'</span>=&gt;<span class="hljs-variable">$theUser</span>-&gt;id,<span class="hljs-string">'name'</span>=&gt;<span class="hljs-variable">$username</span>]);</div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="35"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line">            <span class="hljs-keyword">return</span> <span class="hljs-title function_ invoke__">response</span>()-&gt;<span class="hljs-title function_ invoke__">json</span>([<span class="hljs-string">'code'</span> =&gt; <span class="hljs-number">1</span>, <span class="hljs-string">'msg'</span> =&gt; <span class="hljs-string">'登录成功'</span>]);</div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="36"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line">        }<span class="hljs-keyword">else</span>{</div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="37"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line">            <span class="hljs-keyword">return</span> <span class="hljs-title function_ invoke__">response</span>()-&gt;<span class="hljs-title function_ invoke__">json</span>([<span class="hljs-string">'code'</span> =&gt; <span class="hljs-number">0</span>, <span class="hljs-string">'msg'</span> =&gt; <span class="hljs-string">'登录失败'</span>]);</div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="38"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line">        }</div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="39"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line">    }</div></div></li></ol></code><div class="hljs-button {2}" data-title="复制" onclick="hljs.copyCode(event)"></div></pre> 
<p>（3）在上述代码中使用的一些类需要导入命名空间，具体代码如下：</p> 
<pre data-index="27" class="set-code-show" name="code"><code class="language-php hljs"><ol class="hljs-ln" style="width:100%"><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="1"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line"><span class="hljs-keyword">use</span> <span class="hljs-title">App</span>\<span class="hljs-title">Admin</span>;</div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="2"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line"><span class="hljs-keyword">use</span> <span class="hljs-title">Illuminate</span>\<span class="hljs-title">Support</span>\<span class="hljs-title">Facades</span>\<span class="hljs-title">Session</span>;</div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="3"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line"><span class="hljs-keyword">use</span> <span class="hljs-title">Illuminate</span>\<span class="hljs-title">Support</span>\<span class="hljs-title">Facades</span>\<span class="hljs-title">Validator</span>;</div></div></li></ol></code><div class="hljs-button {2}" data-title="复制" onclick="hljs.copyCode(event)"></div></pre> 
<p>（4）在<strong>login.blade.php</strong>的&lt;script&gt;标签中添加代码，具体代码如下：</p> 
<pre data-index="28" class="set-code-show" name="code"><code class="language-php hljs"><ol class="hljs-ln" style="width:100%"><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="1"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line"> main.<span class="hljs-title function_ invoke__">ajaxForm</span>(<span class="hljs-string">'.j-login'</span>, function() {</div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="2"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line">    location.href = <span class="hljs-string">'/index.php/admin/index'</span>;</div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="3"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line">  });</div></div></li></ol></code><div class="hljs-button {2}" data-title="复制" onclick="hljs.copyCode(event)"></div></pre> 
<p>（5）通过浏览器访问，输入小于6位的密码，页面出现“密码最少为6位”的错误提示；输入验证码不正确，页面出现“验证码有误”的错误提示;如果提交正确的用户名（admin）和密码（123456），页面中会出现“登录成功”的提示。</p> 
<p><img alt="" height="515" src="https://img-blog.csdnimg.cn/a5a24b5f4f944b15ab78f1dbad89f9de.png" width="1200"></p> 
<p>&nbsp;<img alt="" height="557" src="https://img-blog.csdnimg.cn/790d5897f1324699b801e96f2cd8a29b.png" width="1200"></p> 
<p>&nbsp;<img alt="" height="542" src="https://img-blog.csdnimg.cn/a9b7224d52d24916ba8b5a73a63fdb48.png" width="1200"></p> 
<h4 id="%C2%A05.%E7%94%A8%E6%88%B7%E9%80%80%E5%87%BA"><a name="t9"></a>&nbsp;5.用户退出</h4> 
<p>（1）在<strong>User</strong>控制器中添加<strong>logout()</strong>方法，具体代码如下：</p> 
<pre data-index="29" class="set-code-show" name="code"><code class="language-php hljs"><ol class="hljs-ln" style="width:100%"><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="1"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line"> <span class="hljs-keyword">public</span> <span class="hljs-function"><span class="hljs-keyword">function</span> <span class="hljs-title">logout</span>(<span class="hljs-params"></span>)</span>{</div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="2"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line">        <span class="hljs-keyword">if</span>(<span class="hljs-title function_ invoke__">request</span>()-&gt;<span class="hljs-title function_ invoke__">session</span>()-&gt;<span class="hljs-title function_ invoke__">has</span>(<span class="hljs-string">'user'</span>)){</div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="3"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line">            <span class="hljs-title function_ invoke__">request</span>()-&gt;<span class="hljs-title function_ invoke__">session</span>()-&gt;<span class="hljs-title function_ invoke__">pull</span>(<span class="hljs-string">'user'</span>,<span class="hljs-title function_ invoke__">session</span>(<span class="hljs-string">'user'</span>));</div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="4"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line">        }</div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="5"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line">        <span class="hljs-keyword">return</span> <span class="hljs-title function_ invoke__">redirect</span>(<span class="hljs-string">'/admin/login'</span>);</div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="6"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line">    }</div></div></li></ol></code><div class="hljs-button {2}" data-title="复制" onclick="hljs.copyCode(event)"></div></pre> 
<p>（2）在<strong>routes\web.php</strong>文件中添加路由规则，具体代码如下：</p> 
<pre data-index="30" class="set-code-show" name="code"><code class="language-php hljs"><ol class="hljs-ln" style="width:100%"><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="1"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line"><span class="hljs-comment">//用户退出</span></div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="2"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line"><span class="hljs-title class_">Route</span>::<span class="hljs-title function_ invoke__">get</span>(<span class="hljs-string">'/admin/logout'</span>,<span class="hljs-string">'Admin\UserController@logout'</span>);</div></div></li></ol></code><div class="hljs-button {2}" data-title="复制" onclick="hljs.copyCode(event)"></div></pre> 
<p>（3）通过浏览器访问，在确保用户已经登录以后，访问http://cms.com/index.php/admin/logout,浏览器会自动跳转到登录页面，说明已经成功退出。</p> 
<h3 id="%E4%BA%8C%E3%80%81%E5%90%8E%E5%8F%B0%E9%A6%96%E9%A1%B5"><a name="t10"></a>二、后台首页</h3> 
<h4 id="1.%E5%90%8E%E5%8F%B0%E9%A1%B5%E9%9D%A2%E5%B8%83%E5%B1%80"><a name="t11"></a>1.后台页面布局</h4> 
<p>（1）在layouts目录下创建admin.blade.php文件,具体代码如下 ：</p> 
<pre data-index="31" class="set-code-show" name="code"><code class="language-php hljs"><ol class="hljs-ln" style="width:100%"><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="1"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line">&lt;!DOCTYPE html&gt;</div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="2"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line">&lt;html&gt;</div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="3"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line">&lt;head&gt;</div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="4"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line">  &lt;meta charset=<span class="hljs-string">"utf-8"</span>&gt;</div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="5"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line">  &lt;meta name=<span class="hljs-string">"viewport"</span> content=<span class="hljs-string">"width=device-width, initial-scale=1.0"</span>&gt;</div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="6"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line">&lt;!--引入静态文件--&gt;</div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="7"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line">  &lt;title&gt;@<span class="hljs-keyword">yield</span>(<span class="hljs-string">'title'</span>)&lt;/title&gt;</div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="8"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line">&lt;/head&gt;</div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="9"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line">&lt;body&gt;</div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="10"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line">&lt;nav <span class="hljs-class"><span class="hljs-class"><span class="hljs-keyword">class</span>="<span class="hljs-title">navbar</span> <span class="hljs-title">navbar</span>-<span class="hljs-title">expand</span>-<span class="hljs-title">md</span> <span class="hljs-title">navbar</span>-<span class="hljs-title">light</span> <span class="hljs-title">bg</span>-<span class="hljs-title">light</span> <span class="hljs-title">main</span>-<span class="hljs-title">navbar</span>"&gt;</span></span></div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="11"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line"><span class="hljs-class">  &lt;<span class="hljs-title">a</span> <span class="hljs-title">class</span>="<span class="hljs-title">navbar</span>-<span class="hljs-title">brand</span>" <span class="hljs-title">href</span>="#"&gt;后台管理系统&lt;/<span class="hljs-title">a</span>&gt;</span></div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="12"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line"><span class="hljs-class">  &lt;<span class="hljs-title">div</span> <span class="hljs-title">class</span>="<span class="hljs-title">collapse</span> <span class="hljs-title">navbar</span>-<span class="hljs-title">collapse</span>" <span class="hljs-title">id</span>="<span class="hljs-title">navbarSupportedContent</span>"&gt;</span></div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="13"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line"><span class="hljs-class">    &lt;<span class="hljs-title">ul</span> <span class="hljs-title">class</span>="<span class="hljs-title">nav</span> <span class="hljs-title">ml</span>-<span class="hljs-title">auto</span> <span class="hljs-title">main</span>-<span class="hljs-title">nav</span>-<span class="hljs-title">right</span>"&gt;</span></div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="14"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line"><span class="hljs-class">      &lt;<span class="hljs-title">li</span>&gt;</span></div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="15"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line"><span class="hljs-class">        &lt;<span class="hljs-title">a</span> <span class="hljs-title">href</span>="#" <span class="hljs-title">class</span>="<span class="hljs-title">j</span>-<span class="hljs-title">layout</span>-<span class="hljs-title">pwd</span>"&gt;</span></div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="16"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line"><span class="hljs-class">          &lt;<span class="hljs-title">i</span> <span class="hljs-title">class</span>="<span class="hljs-title">fa</span> <span class="hljs-title">fa</span>-<span class="hljs-title">user</span> <span class="hljs-title">fa</span>-<span class="hljs-title">fw</span>"&gt;&lt;/<span class="hljs-title">i</span>&gt;</span>{{<span class="hljs-title function_ invoke__">session</span>()-&gt;<span class="hljs-title function_ invoke__">get</span>(<span class="hljs-string">'user.name'</span>)}}</div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="17"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line">        &lt;/a&gt;</div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="18"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line">      &lt;/li&gt;</div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="19"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line">      &lt;li&gt;</div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="20"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line">        &lt;a href=<span class="hljs-string">"{{url('admin/logout')}}"</span>&gt;</div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="21"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line">          &lt;i <span class="hljs-class"><span class="hljs-class"><span class="hljs-keyword">class</span>="<span class="hljs-title">fa</span> <span class="hljs-title">fa</span>-<span class="hljs-title">power</span>-<span class="hljs-title">off</span> <span class="hljs-title">fa</span>-<span class="hljs-title">fw</span>"&gt;&lt;/<span class="hljs-title">i</span>&gt;退出</span></span></div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="22"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line"><span class="hljs-class">        &lt;/<span class="hljs-title">a</span>&gt;</span></div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="23"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line"><span class="hljs-class">      &lt;/<span class="hljs-title">li</span>&gt;</span></div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="24"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line"><span class="hljs-class">    &lt;/<span class="hljs-title">ul</span>&gt;</span></div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="25"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line"><span class="hljs-class">  &lt;/<span class="hljs-title">div</span>&gt;</span></div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="26"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line"><span class="hljs-class">&lt;/<span class="hljs-title">nav</span>&gt;</span></div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="27"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line"><span class="hljs-class">&lt;!-- 后台页面的首页部分 --&gt;</span></div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="28"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line"><span class="hljs-class">&lt;<span class="hljs-title">div</span> <span class="hljs-title">class</span>="<span class="hljs-title">main</span>-<span class="hljs-title">container</span>"&gt;</span></div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="29"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line"><span class="hljs-class">  &lt;<span class="hljs-title">div</span> <span class="hljs-title">class</span>="<span class="hljs-title">main</span>-<span class="hljs-title">content</span>"&gt;</span></div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="30"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line"><span class="hljs-class">    &lt;<span class="hljs-title">div</span>&gt;@<span class="hljs-title">yield</span>('<span class="hljs-title">main</span>')&lt;/<span class="hljs-title">div</span>&gt;</span></div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="31"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line"><span class="hljs-class">  &lt;/<span class="hljs-title">div</span>&gt;</span></div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="32"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line"><span class="hljs-class">&lt;/<span class="hljs-title">div</span>&gt;</span></div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="33"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line"><span class="hljs-class">&lt;/<span class="hljs-title">body</span>&gt;</span></div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="34"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line"><span class="hljs-class">&lt;/<span class="hljs-title">html</span>&gt;</span></div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="35"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line"><span class="hljs-class"></span></div></div></li></ol></code><div class="hljs-button {2}" data-title="复制" onclick="hljs.copyCode(event)"></div></pre> 
<p>（2）在页面引入静态资源，具体代码如下：</p> 
<pre data-index="32" class="set-code-show" name="code"><code class="language-php hljs"><ol class="hljs-ln" style="width:100%"><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="1"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line">  &lt;link rel=<span class="hljs-string">"stylesheet"</span> href=<span class="hljs-string">"{{asset('admin')}}/common/twitter-bootstrap/4.4.1/css/bootstrap.min.css"</span>&gt;</div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="2"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line">  &lt;link rel=<span class="hljs-string">"stylesheet"</span> href=<span class="hljs-string">"{{asset('admin')}}/common/font-awesome-4.2.0/css/font-awesome.min.css"</span>&gt;</div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="3"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line">  &lt;link rel=<span class="hljs-string">"stylesheet"</span> href=<span class="hljs-string">"{{asset('admin')}}/common/toastr.js/2.1.4/toastr.min.css"</span>&gt;</div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="4"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line">  &lt;link rel=<span class="hljs-string">"stylesheet"</span> href=<span class="hljs-string">"{{asset('admin')}}/css/main.css"</span>&gt;</div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="5"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line">  &lt;script src=<span class="hljs-string">"{{asset('admin')}}/common/jquery/1.12.4/jquery.min.js"</span>&gt;&lt;/script&gt;</div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="6"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line">  &lt;script src=<span class="hljs-string">"{{asset('admin')}}/common/twitter-bootstrap/4.4.1/js/bootstrap.min.js"</span>&gt;&lt;/script&gt;</div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="7"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line">  &lt;script src=<span class="hljs-string">"{{asset('admin')}}/common/toastr.js/2.1.4/toastr.min.js"</span>&gt;&lt;/script&gt;</div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="8"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line">  &lt;script src=<span class="hljs-string">"{{asset('admin')}}/js/main.js"</span>&gt;&lt;/script&gt;</div></div></li></ol></code><div class="hljs-button {2}" data-title="复制" onclick="hljs.copyCode(event)"></div></pre> 
<p>&nbsp;（3）在页面中定义左侧导航栏，具体代码如下：</p> 
<pre data-index="33" class="set-code-show" name="code"><code class="language-php hljs"><ol class="hljs-ln" style="width:100%"><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="1"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line">&lt;div <span class="hljs-class"><span class="hljs-class"><span class="hljs-keyword">class</span>="<span class="hljs-title">main</span>-<span class="hljs-title">sidebar</span>"&gt;</span></span></div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="2"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line"><span class="hljs-class">      &lt;<span class="hljs-title">ul</span> <span class="hljs-title">class</span>="<span class="hljs-title">nav</span> <span class="hljs-title">flex</span>-<span class="hljs-title">column</span> <span class="hljs-title">main</span>-<span class="hljs-title">menu</span>"&gt;</span></div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="3"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line"><span class="hljs-class">      </span></div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="4"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line"><span class="hljs-class">&lt;/<span class="hljs-title">div</span>&gt;</span></div></div></li></ol></code><div class="hljs-button {2}" data-title="复制" onclick="hljs.copyCode(event)"></div></pre> 
<p>（4）添加首页菜单，具体代码如下:</p> 
<p></p> 
<pre data-index="34" class="set-code-show" name="code"><code class="language-php hljs"><ol class="hljs-ln" style="width:100%"><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="1"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line">        &lt;li <span class="hljs-class"><span class="hljs-class"><span class="hljs-keyword">class</span>=""&gt;</span></span></div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="2"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line"><span class="hljs-class">          &lt;<span class="hljs-title">a</span> <span class="hljs-title">href</span>="</span>{{<span class="hljs-title function_ invoke__">url</span>(<span class="hljs-string">'admin/index'</span>)}}<span class="hljs-string">" class="</span>active<span class="hljs-string"><span class="hljs-string">"&gt;</span></span></div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="3"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line"><span class="hljs-string">            &lt;i class="</span>fa fa-home fa-fw<span class="hljs-string"><span class="hljs-string">"&gt;&lt;/i&gt;首页</span></span></div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="4"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line"><span class="hljs-string">          &lt;/a&gt;</span></div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="5"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line"><span class="hljs-string">        &lt;/li&gt;</span></div></div></li></ol></code><div class="hljs-button {2}" data-title="复制" onclick="hljs.copyCode(event)"></div></pre> 
<p>（5） 添加栏目菜单，具体代码如下：</p> 
<pre data-index="35" class="set-code-show" name="code"><code class="language-php hljs"><ol class="hljs-ln" style="width:100%"><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="1"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line">        &lt;li <span class="hljs-class"><span class="hljs-class"><span class="hljs-keyword">class</span>="<span class="hljs-title">main</span>-<span class="hljs-title">sidebar</span>-<span class="hljs-title">collapse</span>"&gt;  &lt;!-- 被收起的双层项 --&gt;</span></span></div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="2"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line"><span class="hljs-class">          &lt;<span class="hljs-title">a</span> <span class="hljs-title">href</span>="#" <span class="hljs-title">class</span>="<span class="hljs-title">main</span>-<span class="hljs-title">sidebar</span>-<span class="hljs-title">collapse</span>-<span class="hljs-title">btn</span>"&gt;   &lt;!-- 链接用于展开或收起子菜单 --&gt;</span></div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="3"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line"><span class="hljs-class">              &lt;<span class="hljs-title">i</span> <span class="hljs-title">class</span>="<span class="hljs-title">fa</span> <span class="hljs-title">fa</span>-<span class="hljs-title">list</span>-<span class="hljs-title">alt</span> <span class="hljs-title">fa</span>-<span class="hljs-title">fw</span>"&gt;&lt;/<span class="hljs-title">i</span>&gt;栏目</span></div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="4"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line"><span class="hljs-class">              &lt;<span class="hljs-title">span</span> <span class="hljs-title">class</span>="<span class="hljs-title">fa</span> <span class="hljs-title">main</span>-<span class="hljs-title">sidebar</span>-<span class="hljs-title">arrow</span>"&gt;&lt;/<span class="hljs-title">span</span>&gt;  &lt;!-- 双层项的右侧小箭头 --&gt;</span></div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="5"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line"><span class="hljs-class">          &lt;/<span class="hljs-title">a</span>&gt;</span></div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="6"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line"><span class="hljs-class">          &lt;<span class="hljs-title">ul</span> <span class="hljs-title">class</span>="<span class="hljs-title">nav</span>"&gt;</span></div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="7"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line"><span class="hljs-class">            &lt;!-- 设置子菜单 --&gt;</span></div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="8"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line"><span class="hljs-class">            &lt;<span class="hljs-title">li</span>&gt;</span></div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="9"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line"><span class="hljs-class">              &lt;<span class="hljs-title">a</span> <span class="hljs-title">href</span>="#" <span class="hljs-title">data</span>-<span class="hljs-title">name</span>="<span class="hljs-title">addcategory</span>"&gt;</span></div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="10"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line"><span class="hljs-class">              &lt;<span class="hljs-title">i</span> <span class="hljs-title">class</span>="<span class="hljs-title">fa</span> <span class="hljs-title">fa</span>-<span class="hljs-title">list</span> <span class="hljs-title">fa</span>-<span class="hljs-title">fw</span>"&gt;&lt;/<span class="hljs-title">i</span>&gt;添加&lt;/<span class="hljs-title">a</span>&gt;</span></div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="11"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line"><span class="hljs-class">            &lt;/<span class="hljs-title">li</span>&gt;</span></div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="12"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line"><span class="hljs-class">            &lt;<span class="hljs-title">li</span>&gt;</span></div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="13"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line"><span class="hljs-class">              &lt;<span class="hljs-title">a</span> <span class="hljs-title">href</span>="#" <span class="hljs-title">data</span>-<span class="hljs-title">name</span>="<span class="hljs-title">category</span>"&gt;</span></div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="14"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line"><span class="hljs-class">                &lt;<span class="hljs-title">i</span> <span class="hljs-title">class</span>="<span class="hljs-title">fa</span> <span class="hljs-title">fa</span>-<span class="hljs-title">table</span> <span class="hljs-title">fa</span>-<span class="hljs-title">fw</span>"&gt;&lt;/<span class="hljs-title">i</span>&gt;列表&lt;/<span class="hljs-title">a</span>&gt;</span></div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="15"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line"><span class="hljs-class">            &lt;/<span class="hljs-title">li</span>&gt;</span></div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="16"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line"><span class="hljs-class">          &lt;/<span class="hljs-title">ul</span>&gt;</span></div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="17"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line"><span class="hljs-class">        &lt;/<span class="hljs-title">li</span>&gt;</span></div></div></li></ol></code><div class="hljs-button {2}" data-title="复制" onclick="hljs.copyCode(event)"></div></pre> 
<p>（6）添加内容表单，具体代码如下：</p> 
<pre data-index="36" class="set-code-show" name="code"><code class="language-php hljs"><ol class="hljs-ln" style="width:100%"><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="1"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line">        &lt;li <span class="hljs-class"><span class="hljs-class"><span class="hljs-keyword">class</span>="<span class="hljs-title">main</span>-<span class="hljs-title">sidebar</span>-<span class="hljs-title">collapse</span>"&gt;</span></span></div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="2"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line"><span class="hljs-class">          &lt;<span class="hljs-title">a</span> <span class="hljs-title">href</span>="#" <span class="hljs-title">class</span>="<span class="hljs-title">main</span>-<span class="hljs-title">sidebar</span>-<span class="hljs-title">collapse</span>-<span class="hljs-title">btn</span>"&gt;</span></div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="3"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line"><span class="hljs-class">            &lt;<span class="hljs-title">i</span> <span class="hljs-title">class</span>="<span class="hljs-title">fa</span> <span class="hljs-title">fa</span>-<span class="hljs-title">list</span>-<span class="hljs-title">alt</span> <span class="hljs-title">fa</span>-<span class="hljs-title">fw</span>"&gt;&lt;/<span class="hljs-title">i</span>&gt;内容</span></div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="4"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line"><span class="hljs-class">            &lt;<span class="hljs-title">span</span> <span class="hljs-title">class</span>="<span class="hljs-title">fa</span> <span class="hljs-title">main</span>-<span class="hljs-title">sidebar</span>-<span class="hljs-title">arrow</span>"&gt;&lt;/<span class="hljs-title">span</span>&gt;</span></div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="5"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line"><span class="hljs-class">          &lt;/<span class="hljs-title">a</span>&gt;</span></div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="6"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line"><span class="hljs-class">          &lt;<span class="hljs-title">ul</span> <span class="hljs-title">class</span>="<span class="hljs-title">nav</span>"&gt;</span></div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="7"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line"><span class="hljs-class">            &lt;<span class="hljs-title">li</span>&gt;</span></div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="8"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line"><span class="hljs-class">              &lt;<span class="hljs-title">a</span> <span class="hljs-title">href</span>="#" <span class="hljs-title">data</span>-<span class="hljs-title">name</span>="<span class="hljs-title">addcontent</span>"&gt;</span></div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="9"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line"><span class="hljs-class">              &lt;<span class="hljs-title">i</span> <span class="hljs-title">class</span>="<span class="hljs-title">fa</span> <span class="hljs-title">fa</span>-<span class="hljs-title">list</span> <span class="hljs-title">fa</span>-<span class="hljs-title">fw</span>"&gt;&lt;/<span class="hljs-title">i</span>&gt;添加&lt;/<span class="hljs-title">a</span>&gt;</span></div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="10"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line"><span class="hljs-class">            &lt;/<span class="hljs-title">li</span>&gt;</span></div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="11"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line"><span class="hljs-class">            &lt;<span class="hljs-title">li</span>&gt;</span></div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="12"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line"><span class="hljs-class">              &lt;<span class="hljs-title">a</span> <span class="hljs-title">href</span>="#" <span class="hljs-title">data</span>-<span class="hljs-title">name</span>="<span class="hljs-title">content</span>"&gt;</span></div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="13"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line"><span class="hljs-class">                &lt;<span class="hljs-title">i</span> <span class="hljs-title">class</span>="<span class="hljs-title">fa</span> <span class="hljs-title">fa</span>-<span class="hljs-title">table</span> <span class="hljs-title">fa</span>-<span class="hljs-title">fw</span>"&gt;&lt;/<span class="hljs-title">i</span>&gt;列表&lt;/<span class="hljs-title">a</span>&gt;</span></div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="14"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line"><span class="hljs-class">            &lt;/<span class="hljs-title">li</span>&gt;</span></div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="15"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line"><span class="hljs-class">          &lt;/<span class="hljs-title">ul</span>&gt;</span></div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="16"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line"><span class="hljs-class">        &lt;/<span class="hljs-title">li</span>&gt;</span></div></div></li></ol></code><div class="hljs-button {2}" data-title="复制" onclick="hljs.copyCode(event)"></div></pre> 
<p>&nbsp;（7）添加广告表单，具体代码如下：</p> 
<pre data-index="37" class="set-code-show" name="code"><code class="language-php hljs"><ol class="hljs-ln" style="width:100%"><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="1"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line">         &lt;li <span class="hljs-class"><span class="hljs-class"><span class="hljs-keyword">class</span>="<span class="hljs-title">main</span>-<span class="hljs-title">sidebar</span>-<span class="hljs-title">collapse</span>"&gt;</span></span></div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="2"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line"><span class="hljs-class">          &lt;<span class="hljs-title">a</span> <span class="hljs-title">href</span>="#" <span class="hljs-title">class</span>="<span class="hljs-title">main</span>-<span class="hljs-title">sidebar</span>-<span class="hljs-title">collapse</span>-<span class="hljs-title">btn</span>"&gt;</span></div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="3"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line"><span class="hljs-class">            &lt;<span class="hljs-title">i</span> <span class="hljs-title">class</span>="<span class="hljs-title">fa</span> <span class="hljs-title">fa</span>-<span class="hljs-title">cog</span> <span class="hljs-title">fa</span>-<span class="hljs-title">fw</span>"&gt;&lt;/<span class="hljs-title">i</span>&gt;广告</span></div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="4"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line"><span class="hljs-class">            &lt;<span class="hljs-title">span</span> <span class="hljs-title">class</span>="<span class="hljs-title">fa</span> <span class="hljs-title">main</span>-<span class="hljs-title">sidebar</span>-<span class="hljs-title">arrow</span>"&gt;&lt;/<span class="hljs-title">span</span>&gt;</span></div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="5"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line"><span class="hljs-class">          &lt;/<span class="hljs-title">a</span>&gt;</span></div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="6"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line"><span class="hljs-class">          &lt;<span class="hljs-title">ul</span> <span class="hljs-title">class</span>="<span class="hljs-title">nav</span>"&gt;</span></div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="7"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line"><span class="hljs-class">            &lt;<span class="hljs-title">li</span>&gt;</span></div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="8"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line"><span class="hljs-class">              &lt;<span class="hljs-title">a</span> <span class="hljs-title">href</span>="#" <span class="hljs-title">data</span>-<span class="hljs-title">name</span>="<span class="hljs-title">adv</span>"&gt;</span></div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="9"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line"><span class="hljs-class">                &lt;<span class="hljs-title">i</span> <span class="hljs-title">class</span>="<span class="hljs-title">fa</span> <span class="hljs-title">fa</span>-<span class="hljs-title">list</span> <span class="hljs-title">fa</span>-<span class="hljs-title">fw</span>"&gt;&lt;/<span class="hljs-title">i</span>&gt;广告位&lt;/<span class="hljs-title">a</span>&gt;</span></div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="10"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line"><span class="hljs-class">            &lt;/<span class="hljs-title">li</span>&gt;</span></div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="11"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line"><span class="hljs-class">            &lt;<span class="hljs-title">li</span>&gt;</span></div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="12"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line"><span class="hljs-class">              &lt;<span class="hljs-title">a</span> <span class="hljs-title">href</span>="#" <span class="hljs-title">data</span>-<span class="hljs-title">name</span>="<span class="hljs-title">advcontent</span>"&gt;</span></div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="13"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line"><span class="hljs-class">                &lt;<span class="hljs-title">i</span> <span class="hljs-title">class</span>="<span class="hljs-title">fa</span> <span class="hljs-title">fa</span>-<span class="hljs-title">list</span>-<span class="hljs-title">alt</span> <span class="hljs-title">fa</span>-<span class="hljs-title">fw</span>"&gt;&lt;/<span class="hljs-title">i</span>&gt;广告内容&lt;/<span class="hljs-title">a</span>&gt;</span></div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="14"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line"><span class="hljs-class">           &lt;/<span class="hljs-title">li</span>&gt;</span></div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="15"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line"><span class="hljs-class">          &lt;/<span class="hljs-title">ul</span>&gt;</span></div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="16"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line"><span class="hljs-class">        &lt;/<span class="hljs-title">li</span>&gt;</span></div></div></li></ol></code><div class="hljs-button {2}" data-title="复制" onclick="hljs.copyCode(event)"></div></pre> 
<p>&nbsp;（8）添加消息表单，具体代码如下：</p> 
<pre data-index="38" class="set-code-show" name="code"><code class="language-php hljs"><ol class="hljs-ln" style="width:100%"><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="1"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line">@<span class="hljs-keyword">if</span>(!<span class="hljs-keyword">empty</span>(<span class="hljs-title function_ invoke__">session</span>(<span class="hljs-string">'message'</span>)))</div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="2"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line">  &lt;div <span class="hljs-class"><span class="hljs-keyword">class</span>="<span class="hljs-title">alert</span> <span class="hljs-title">alert</span>-<span class="hljs-title">success</span>" <span class="hljs-title">role</span>="<span class="hljs-title">alert</span>"</span></div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="3"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line">    <span class="hljs-title">style</span>="<span class="hljs-title">text</span>-<span class="hljs-title">align</span>:<span class="hljs-title">center</span>;<span class="hljs-title">margin</span>:0 <span class="hljs-title">auto</span>;<span class="hljs-title">width</span>: 400<span class="hljs-title">px</span>"&gt;</div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="4"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line">      {{<span class="hljs-title function_ invoke__">session</span>(<span class="hljs-string">'message'</span>)}}</div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="5"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line">  &lt;/div&gt;</div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="6"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line">@<span class="hljs-keyword">endif</span></div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="7"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line">@<span class="hljs-keyword">if</span>(!<span class="hljs-keyword">empty</span>(<span class="hljs-title function_ invoke__">session</span>(<span class="hljs-string">'tip'</span>)))</div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="8"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line">  &lt;div <span class="hljs-class"><span class="hljs-keyword">class</span>="<span class="hljs-title">alert</span> <span class="hljs-title">alert</span>-<span class="hljs-title">warning</span>" <span class="hljs-title">role</span>="<span class="hljs-title">alert</span>"</span></div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="9"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line">  <span class="hljs-title">style</span>="<span class="hljs-title">text</span>-<span class="hljs-title">align</span>:<span class="hljs-title">center</span>;<span class="hljs-title">margin</span>:0 <span class="hljs-title">auto</span>;<span class="hljs-title">width</span>: 400<span class="hljs-title">px</span>"&gt;</div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="10"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line">    {{<span class="hljs-title function_ invoke__">session</span>(<span class="hljs-string">'tip'</span>)}}</div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="11"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line">  &lt;/div&gt;</div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="12"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line">@<span class="hljs-keyword">endif</span></div></div></li></ol></code><div class="hljs-button {2}" data-title="复制" onclick="hljs.copyCode(event)"></div></pre> 
<p>（9）在&lt;body&gt;标签结束前的位置添加&lt;script&gt;标签，控制消息模板的显示时间，具体代码如下：</p> 
<pre data-index="39" class="set-code-show" name="code"><code class="language-php hljs"><ol class="hljs-ln" style="width:100%"><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="1"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line">&lt;script&gt;</div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="2"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line">  <span class="hljs-comment">// setInterval(myFunction，myTimeLapse)，每隔myTimeLapse（毫秒）执行一次myFunction()函数</span></div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="3"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line">  <span class="hljs-title function_ invoke__">setInterval</span>(function(){</div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="4"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line">    $(<span class="hljs-string">'.alert'</span>).<span class="hljs-title function_ invoke__">remove</span>();</div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="5"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line">  },<span class="hljs-number">3000</span>);</div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="6"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line">&lt;/script&gt;</div></div></li></ol></code><div class="hljs-button {2}" data-title="复制" onclick="hljs.copyCode(event)"></div></pre> 
<p>（10） 修改<strong>public\admin\js\main.js</strong>文件，编写layout()方法，具体代码如下：</p> 
<pre data-index="40" class="set-code-show" name="code"><code class="language-php hljs"><ol class="hljs-ln" style="width:100%"><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="1"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line"> layout: <span class="hljs-function"><span class="hljs-keyword">function</span>(<span class="hljs-params"></span>) </span>{</div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="2"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line">      $(<span class="hljs-string">'.main-sidebar-collapse-btn'</span>).<span class="hljs-title function_ invoke__">click</span>(function() {</div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="3"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line">        $(this).<span class="hljs-built_in">parent</span>().<span class="hljs-title function_ invoke__">find</span>(<span class="hljs-string">'.nav'</span>).<span class="hljs-title function_ invoke__">slideToggle</span>(<span class="hljs-number">200</span>);</div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="4"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line">        $(this).<span class="hljs-built_in">parent</span>().<span class="hljs-title function_ invoke__">toggleClass</span>(<span class="hljs-string">'main-sidebar-collapse'</span>).<span class="hljs-title function_ invoke__">siblings</span>().</div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="5"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line">            <span class="hljs-title function_ invoke__">addClass</span>(<span class="hljs-string">'main-sidebar-collapse'</span>).<span class="hljs-title function_ invoke__">find</span>(<span class="hljs-string">'.nav'</span>).<span class="hljs-title function_ invoke__">slideUp</span>(<span class="hljs-number">200</span>);</div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="6"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line">        <span class="hljs-keyword">return</span> <span class="hljs-literal">false</span>;</div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="7"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line">      });</div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="8"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line">    },</div></div></li></ol></code><div class="hljs-button {2}" data-title="复制" onclick="hljs.copyCode(event)"></div></pre> 
<p>（11）在<strong>main.js</strong>中增加<strong>menuActive()</strong>方法，用于将指定菜单项设为选中效果，具体代码如下：</p> 
<pre data-index="41" class="set-code-show" name="code"><code class="language-php hljs"><ol class="hljs-ln" style="width:100%"><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="1"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line">menuActive: <span class="hljs-function"><span class="hljs-keyword">function</span>(<span class="hljs-params">name</span>) </span>{</div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="2"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line">      <span class="hljs-keyword">var</span> menu = $(<span class="hljs-string">'.main-menu'</span>);</div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="3"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line">      menu.<span class="hljs-title function_ invoke__">find</span>(<span class="hljs-string">'a'</span>).<span class="hljs-title function_ invoke__">removeClass</span>(<span class="hljs-string">'active'</span>);</div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="4"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line">      menu.<span class="hljs-title function_ invoke__">find</span>(<span class="hljs-string">'a[data-name=\''</span> + name + <span class="hljs-string">'\']'</span>).<span class="hljs-title function_ invoke__">addClass</span>(<span class="hljs-string">'active'</span>);</div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="5"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line">      menu.<span class="hljs-title function_ invoke__">find</span>(<span class="hljs-string">'a[data-name=\''</span> + name + <span class="hljs-string">'\']'</span>).<span class="hljs-built_in">parent</span>().<span class="hljs-built_in">parent</span>().<span class="hljs-title function_ invoke__">show</span>();</div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="6"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line">    }</div></div></li></ol></code><div class="hljs-button {2}" data-title="复制" onclick="hljs.copyCode(event)"></div></pre> 
<p>（12）在&lt;script&gt;标签中调用<strong>layout()</strong>方法，具体代码如下：</p> 
<pre data-index="42" class="set-code-show" name="code"><code class="language-php hljs">main.<span class="hljs-title function_ invoke__">layout</span>();</code><div class="hljs-button {2}" data-title="复制" onclick="hljs.copyCode(event)"></div></pre> 
<h4 id="2.%E6%98%BE%E7%A4%BA%E5%90%8E%E5%8F%B0%E9%A6%96%E9%A1%B5"><a name="t12"></a>2.显示后台首页</h4> 
<p>（1）公共文件创建完成后，接下来创建后台首页admin\index.blade.php,具体代码如下：</p> 
<pre data-index="43" class="set-code-show" name="code"><code class="language-php hljs"><ol class="hljs-ln" style="width:100%"><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="1"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line">@<span class="hljs-keyword">extends</span>(<span class="hljs-string">'admin/layouts/admin'</span>)</div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="2"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line">@<span class="hljs-title function_ invoke__">section</span>(<span class="hljs-string">'title'</span>, <span class="hljs-string">'后台首页'</span>)</div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="3"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line">@<span class="hljs-title function_ invoke__">section</span>(<span class="hljs-string">'main'</span>)</div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="4"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line">  &lt;div&gt;</div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="5"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line">    &lt;div <span class="hljs-class"><span class="hljs-class"><span class="hljs-keyword">class</span>="<span class="hljs-title">main</span>-<span class="hljs-title">title</span>"&gt;</span></span></div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="6"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line"><span class="hljs-class">      &lt;<span class="hljs-title">h2</span>&gt;首页&lt;/<span class="hljs-title">h2</span>&gt;</span></div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="7"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line"><span class="hljs-class">    &lt;/<span class="hljs-title">div</span>&gt;</span></div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="8"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line"><span class="hljs-class">    &lt;<span class="hljs-title">div</span> <span class="hljs-title">class</span>="<span class="hljs-title">main</span>-<span class="hljs-title">section</span>"&gt;</span></div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="9"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line"><span class="hljs-class">      &lt;<span class="hljs-title">div</span> <span class="hljs-title">class</span>="<span class="hljs-title">card</span>"&gt;</span></div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="10"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line"><span class="hljs-class">        &lt;<span class="hljs-title">div</span> <span class="hljs-title">class</span>="<span class="hljs-title">card</span>-<span class="hljs-title">header</span>"&gt;服务器信息&lt;/<span class="hljs-title">div</span>&gt;</span></div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="11"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line"><span class="hljs-class">        &lt;<span class="hljs-title">ul</span> <span class="hljs-title">class</span>="<span class="hljs-title">list</span>-<span class="hljs-title">group</span> <span class="hljs-title">list</span>-<span class="hljs-title">group</span>-<span class="hljs-title">flush</span>"&gt;</span></div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="12"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line"><span class="hljs-class">          &lt;<span class="hljs-title">li</span> <span class="hljs-title">class</span>="<span class="hljs-title">list</span>-<span class="hljs-title">group</span>-<span class="hljs-title">item</span>"&gt;系统环境：</span>{{ <span class="hljs-variable">$server_version</span> }}&lt;/li&gt;</div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="13"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line">          &lt;li <span class="hljs-class"><span class="hljs-keyword">class</span>="<span class="hljs-title">list</span>-<span class="hljs-title">group</span>-<span class="hljs-title">item</span>"&gt;<span class="hljs-title">Laravel</span>版本：</span>{{ <span class="hljs-variable">$laravel_version</span> }}&lt;/li&gt;</div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="14"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line">          &lt;li <span class="hljs-class"><span class="hljs-keyword">class</span>="<span class="hljs-title">list</span>-<span class="hljs-title">group</span>-<span class="hljs-title">item</span>"&gt;<span class="hljs-title">MySQL</span>版本：</span>{{ <span class="hljs-variable">$mysql_version</span> }}&lt;/li&gt;</div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="15"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line">          &lt;li <span class="hljs-class"><span class="hljs-keyword">class</span>="<span class="hljs-title">list</span>-<span class="hljs-title">group</span>-<span class="hljs-title">item</span>"&gt;服务器时间：</span>{{ <span class="hljs-variable">$server_time</span> }}&lt;/li&gt;</div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="16"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line">          &lt;li <span class="hljs-class"><span class="hljs-keyword">class</span>="<span class="hljs-title">list</span>-<span class="hljs-title">group</span>-<span class="hljs-title">item</span>"&gt;文件上传限制：</span>{{ <span class="hljs-variable">$upload_max_filesize</span> }}&lt;/li&gt;</div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="17"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line">          &lt;li <span class="hljs-class"><span class="hljs-keyword">class</span>="<span class="hljs-title">list</span>-<span class="hljs-title">group</span>-<span class="hljs-title">item</span>"&gt;脚本执行时限：</span>{{ <span class="hljs-variable">$max_execution_time</span> }}&lt;/li&gt;</div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="18"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line">        &lt;/ul&gt;</div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="19"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line">      &lt;/div&gt;</div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="20"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line">    &lt;/div&gt;</div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="21"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line">  &lt;/div&gt;</div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="22"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line">@endsection</div></div></li></ol></code><div class="hljs-button {2}" data-title="复制" onclick="hljs.copyCode(event)"></div></pre> 
<p>（2）创建<strong>Index</strong>控制器，具体代码如下：</p> 
<pre data-index="44" class="set-code-show" name="code"><code class="language-php hljs">php artisan make:controller Admin\IndexController</code><div class="hljs-button {2}" data-title="复制" onclick="hljs.copyCode(event)"></div></pre> 
<p>（3） 在Index控制器中添加<strong>index()</strong>方法，具体代码如下：</p> 
<pre data-index="45" class="set-code-show" name="code"><code class="language-php hljs"><ol class="hljs-ln" style="width:100%"><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="1"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line">    <span class="hljs-keyword">public</span> <span class="hljs-function"><span class="hljs-keyword">function</span> <span class="hljs-title">index</span>(<span class="hljs-params">Request <span class="hljs-variable">$request</span></span>)</span>{</div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="2"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line">        <span class="hljs-variable">$data</span> = [</div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="3"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line">            <span class="hljs-string">'server_version'</span> =&gt; <span class="hljs-variable">$request</span>-&gt;<span class="hljs-title function_ invoke__">server</span>(<span class="hljs-string">'SERVER_SOFTWARE'</span>),</div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="4"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line">            <span class="hljs-string">'laravel_version'</span> =&gt; <span class="hljs-title function_ invoke__">app</span>()::<span class="hljs-variable constant_">VERSION</span>,</div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="5"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line">            <span class="hljs-string">'mysql_version'</span> =&gt; <span class="hljs-variable language_">$this</span>-&gt;<span class="hljs-title function_ invoke__">getMySQLVer</span>(),</div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="6"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line">            <span class="hljs-string">'server_time'</span> =&gt; <span class="hljs-title function_ invoke__">date</span>(<span class="hljs-string">'Y-m-d H:i:s'</span>, <span class="hljs-title function_ invoke__">time</span>()),</div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="7"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line">            <span class="hljs-string">'upload_max_filesize'</span> =&gt; <span class="hljs-title function_ invoke__">ini_get</span>(<span class="hljs-string">'file_uploads'</span>) ?</div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="8"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line">                <span class="hljs-title function_ invoke__">ini_get</span>(<span class="hljs-string">'upload_max_filesize'</span>) : <span class="hljs-string">'已禁用'</span>,</div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="9"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line">            <span class="hljs-string">'max_execution_time'</span> =&gt; <span class="hljs-title function_ invoke__">ini_get</span>(<span class="hljs-string">'max_execution_time'</span>) . <span class="hljs-string">'秒'</span></div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="10"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line">        ];</div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="11"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line">        <span class="hljs-keyword">return</span> <span class="hljs-title function_ invoke__">view</span>(<span class="hljs-string">'admin\index'</span>, <span class="hljs-variable">$data</span>);</div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="12"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line">    }</div></div></li></ol></code><div class="hljs-button {2}" data-title="复制" onclick="hljs.copyCode(event)"></div></pre> 
<p>（4）在上述代码中，第六行代码调用<strong>getMySQLVer()</strong>方法获取MySQL版本，创建getMySQLVer()方法，具体代码如下：</p> 
<pre data-index="46" class="set-code-show" name="code"><code class="language-php hljs"><ol class="hljs-ln" style="width:100%"><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="1"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line"><span class="hljs-keyword">private</span> <span class="hljs-function"><span class="hljs-keyword">function</span> <span class="hljs-title">getMySQLVer</span>(<span class="hljs-params"></span>)</span></div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="2"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line">    {</div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="3"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line">        <span class="hljs-variable">$res</span> = DB::<span class="hljs-title function_ invoke__">select</span>(<span class="hljs-string">'SELECT VERSION() AS ver'</span>);</div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="4"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line">        <span class="hljs-keyword">return</span> <span class="hljs-variable">$res</span>[<span class="hljs-number">0</span>]-&gt;ver ?? <span class="hljs-string">'未知'</span>;</div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="5"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line">    }</div></div></li></ol></code><div class="hljs-button {2}" data-title="复制" onclick="hljs.copyCode(event)"></div></pre> 
<p>&nbsp;（5）在getMySQLVer()方法中，使用DB类执行SQL，获取MySQL的版本，导入DB类的命名空间，具体代码如下：</p> 
<pre data-index="47" class="set-code-show" name="code"><code class="language-php hljs"><span class="hljs-keyword">use</span> <span class="hljs-title">DB</span>;</code><div class="hljs-button {2}" data-title="复制" onclick="hljs.copyCode(event)"></div></pre> 
<p>（6）在routes\web.php文件中添加路由规则，具体代码如下：</p> 
<pre data-index="48" class="set-code-show" name="code"><code class="language-php hljs"><span class="hljs-title class_">Route</span>::<span class="hljs-title function_ invoke__">get</span>(<span class="hljs-string">'/admin/index'</span>, <span class="hljs-string">'Admin\IndexController@index'</span>);</code><div class="hljs-button {2}" data-title="复制" onclick="hljs.copyCode(event)"></div></pre> 
<p>&nbsp;（7）通过浏览器访问后台首页，其效果如下图：</p> 
<p><img alt="" height="738" src="https://img-blog.csdnimg.cn/95fdb6fd6d5d4bf5a0c41389f5257685.png" width="1200"></p> 
<p></p> 
<h4 id="3.%E5%88%A4%E6%96%AD%E7%99%BB%E5%BD%95%E7%8A%B6%E6%80%81"><a name="t13"></a>3.判断登录状态</h4> 
<p>（1）创建<strong>Admin中间件</strong>,用于验证用户是否登录,具体代码如下：</p> 
<pre data-index="49" class="set-code-show" name="code"><code class="language-php hljs">php artisan make:middleware Admin</code><div class="hljs-button {2}" data-title="复制" onclick="hljs.copyCode(event)"></div></pre> 
<p>（2）打开<strong>app\Http\Middleware\Admin.php</strong>，添加验证用户登录的代码，具体代码如下：</p> 
<pre data-index="50" class="set-code-show" name="code"><code class="language-php hljs"><ol class="hljs-ln" style="width:100%"><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="1"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line"> <span class="hljs-keyword">public</span> <span class="hljs-function"><span class="hljs-keyword">function</span> <span class="hljs-title">handle</span>(<span class="hljs-params"><span class="hljs-variable">$request</span>, <span class="hljs-built_in">Closure</span> <span class="hljs-variable">$next</span></span>)</span></div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="2"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line">    {</div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="3"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line">        <span class="hljs-keyword">if</span> (<span class="hljs-title function_ invoke__">request</span>()-&gt;<span class="hljs-title function_ invoke__">session</span>()-&gt;<span class="hljs-title function_ invoke__">has</span>(<span class="hljs-string">'user'</span>)) {</div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="4"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line">            <span class="hljs-variable">$user</span> = <span class="hljs-title function_ invoke__">request</span>()-&gt;<span class="hljs-title function_ invoke__">session</span>()-&gt;<span class="hljs-title function_ invoke__">get</span>(<span class="hljs-string">'user'</span>);</div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="5"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line">            <span class="hljs-title function_ invoke__">view</span>()-&gt;<span class="hljs-title function_ invoke__">share</span>(<span class="hljs-string">'user'</span>, <span class="hljs-variable">$user</span>);</div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="6"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line">        } <span class="hljs-keyword">else</span> {</div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="7"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line">            <span class="hljs-keyword">return</span> <span class="hljs-title function_ invoke__">redirect</span>(<span class="hljs-string">'/admin/login'</span>);</div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="8"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line">        }</div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="9"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line">        <span class="hljs-keyword">return</span> <span class="hljs-variable">$next</span>(<span class="hljs-variable">$request</span>);</div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="10"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line">    }</div></div></li></ol></code><div class="hljs-button {2}" data-title="复制" onclick="hljs.copyCode(event)"></div></pre> 
<p>（3）在<strong>app\Http\Kernel.php</strong>文件中注册路由中间件，具体代码如下：</p> 
<pre data-index="51" class="set-code-show" name="code"><code class="language-php hljs"><ol class="hljs-ln" style="width:100%"><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="1"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line"><span class="hljs-keyword">protected</span> <span class="hljs-variable">$routeMiddleware</span> = [</div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="2"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line">    ...(原有代码)</div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="3"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line">    <span class="hljs-string">'Admin'</span> =&gt; <span class="hljs-title class_">\App\Http\Middleware\Admin</span>::<span class="hljs-variable language_">class</span>,</div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="4"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line">];</div></div></li></ol></code><div class="hljs-button {2}" data-title="复制" onclick="hljs.copyCode(event)"></div></pre> 
<p>（4）修改首页的路由规则，为后台首页添加用户验证，具体代码如下：</p> 
<pre data-index="52" class="set-code-show" name="code"><code class="language-php hljs"><span class="hljs-title class_">Route</span>::<span class="hljs-title function_ invoke__">get</span>(<span class="hljs-string">'/admin/index'</span>, <span class="hljs-string">'Admin\IndexController@index'</span>)-&gt;<span class="hljs-title function_ invoke__">middleware</span>([<span class="hljs-string">'Admin'</span>]);
</code><div class="hljs-button {2}" data-title="复制" onclick="hljs.copyCode(event)"></div></pre> 
<h3 id="%E4%B8%89%E3%80%81%E6%A0%8F%E7%9B%AE%E7%AE%A1%E7%90%86"><a name="t14"></a>三、栏目管理</h3> 
<h4 id="1.%E5%88%9B%E5%BB%BA%E6%A0%8F%E7%9B%AE%E8%A1%A8"><a name="t15"></a>1.创建栏目表</h4> 
<p>（1）栏目表同样也是通过命令行来创建，按照前面的步骤创建迁移文件和填充文件。</p> 
<p>（2）打开栏目表的迁移文件，在该文件的<strong>up()</strong>方法中添加表结构信息，具体代码如下：</p> 
<pre data-index="53" class="set-code-show" name="code"><code class="language-php hljs"><ol class="hljs-ln" style="width:100%"><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="1"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line"> <span class="hljs-keyword">public</span> <span class="hljs-function"><span class="hljs-keyword">function</span> <span class="hljs-title">up</span>(<span class="hljs-params"></span>)</span></div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="2"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line">    {</div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="3"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line">        </div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="4"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line">        <span class="hljs-title class_">Schema</span>::<span class="hljs-title function_ invoke__">create</span>(<span class="hljs-string">'category'</span>, function (Blueprint <span class="hljs-variable">$table</span>) {</div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="5"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line">            <span class="hljs-variable">$table</span>-&gt;<span class="hljs-title function_ invoke__">increments</span>(<span class="hljs-string">'id'</span>)-&gt;<span class="hljs-title function_ invoke__">comment</span>(<span class="hljs-string">'主键'</span>);</div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="6"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line">            <span class="hljs-variable">$table</span>-&gt;<span class="hljs-keyword">integer</span>(<span class="hljs-string">'pid'</span>)-&gt;<span class="hljs-title function_ invoke__">comment</span>(<span class="hljs-string">'父类id'</span>) -&gt;<span class="hljs-keyword">default</span>(<span class="hljs-string">'0'</span>);</div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="7"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line">            <span class="hljs-variable">$table</span>-&gt;<span class="hljs-keyword">string</span>(<span class="hljs-string">'name'</span>, <span class="hljs-number">32</span>)-&gt;<span class="hljs-title function_ invoke__">comment</span>(<span class="hljs-string">'分类名称'</span>);</div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="8"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line">            <span class="hljs-variable">$table</span>-&gt;<span class="hljs-keyword">integer</span>(<span class="hljs-string">'sort'</span>)-&gt;<span class="hljs-title function_ invoke__">comment</span>(<span class="hljs-string">'排序值'</span>) -&gt;<span class="hljs-keyword">default</span>(<span class="hljs-string">'0'</span>);</div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="9"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line">            <span class="hljs-variable">$table</span>-&gt;<span class="hljs-title function_ invoke__">timestamps</span>();</div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="10"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line">        });</div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="11"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line"> </div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="12"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line"> </div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="13"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line">    }</div></div></li></ol></code><div class="hljs-button {2}" data-title="复制" onclick="hljs.copyCode(event)"></div></pre> 
<p>（3）栏目表创建完成后，为了在项目中操作栏目表，下面创建栏目表对应的模型文件，具体代码如下：</p> 
<pre data-index="54" class="set-code-show" name="code"><code class="language-php hljs">php artisan make:model Category</code><div class="hljs-button {2}" data-title="复制" onclick="hljs.copyCode(event)"></div></pre> 
<p>（4）打开<strong>app\Category.php</strong>文件，具体代码如下：</p> 
<pre data-index="55" class="set-code-show" name="code"><code class="language-php hljs"><ol class="hljs-ln" style="width:100%"><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="1"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line"><span class="hljs-meta">&lt;?php</span></div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="2"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line"> </div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="3"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line"><span class="hljs-keyword">namespace</span> <span class="hljs-title class_">App</span>;</div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="4"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line"> </div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="5"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line"><span class="hljs-keyword">use</span> <span class="hljs-title">Illuminate</span>\<span class="hljs-title">Database</span>\<span class="hljs-title">Eloquent</span>\<span class="hljs-title">Model</span>;</div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="6"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line"> </div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="7"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line"><span class="hljs-class"><span class="hljs-keyword">class</span> <span class="hljs-title">Category</span> <span class="hljs-keyword">extends</span> <span class="hljs-title">Model</span></span></div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="8"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line">{</div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="9"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line">    <span class="hljs-keyword">protected</span> <span class="hljs-variable">$table</span> = <span class="hljs-string">"category"</span>;</div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="10"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line">    <span class="hljs-keyword">public</span> <span class="hljs-variable">$fillable</span> = [<span class="hljs-string">'pid'</span>, <span class="hljs-string">'name'</span>, <span class="hljs-string">'sort'</span>];</div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="11"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line">}</div></div></li></ol></code><div class="hljs-button {2}" data-title="复制" onclick="hljs.copyCode(event)"></div></pre> 
<h4 id="2.%E6%B7%BB%E5%8A%A0%E6%A0%8F%E7%9B%AE"><a name="t16"></a>2.添加栏目</h4> 
<p>（1）创建<strong>Category</strong>控制器，具体代码如下：</p> 
<pre data-index="56" class="set-code-show" name="code"><code class="language-php hljs">php artisan make:controller Admin\CategoryController</code><div class="hljs-button {2}" data-title="复制" onclick="hljs.copyCode(event)"></div></pre> 
<p>（2）在控制器中添加<strong>add()</strong>方法，用于实现添加栏目的功能，具体代码如下：</p> 
<pre data-index="57" class="set-code-show" name="code"><code class="language-php hljs"><ol class="hljs-ln" style="width:100%"><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="1"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line"><span class="hljs-meta">&lt;?php</span></div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="2"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line"> </div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="3"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line"><span class="hljs-keyword">namespace</span> <span class="hljs-title class_">App</span>\<span class="hljs-title class_">Http</span>\<span class="hljs-title class_">Controllers</span>\<span class="hljs-title class_">Admin</span>;</div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="4"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line"> </div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="5"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line"><span class="hljs-keyword">use</span> <span class="hljs-title">Illuminate</span>\<span class="hljs-title">Http</span>\<span class="hljs-title">Request</span>;</div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="6"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line"><span class="hljs-keyword">use</span> <span class="hljs-title">App</span>\<span class="hljs-title">Http</span>\<span class="hljs-title">Controllers</span>\<span class="hljs-title">Controller</span>;</div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="7"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line"><span class="hljs-keyword">use</span> <span class="hljs-title">App</span>\<span class="hljs-title">Category</span>;</div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="8"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line"> </div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="9"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line"><span class="hljs-class"><span class="hljs-keyword">class</span> <span class="hljs-title">CategoryController</span> <span class="hljs-keyword">extends</span> <span class="hljs-title">Controller</span></span></div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="10"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line">{</div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="11"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line">    <span class="hljs-keyword">public</span> <span class="hljs-function"><span class="hljs-keyword">function</span> <span class="hljs-title">add</span>(<span class="hljs-params"></span>)</span>{</div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="12"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line">        <span class="hljs-variable">$category</span> = <span class="hljs-title class_">Category</span>::<span class="hljs-title function_ invoke__">where</span>(<span class="hljs-string">'pid'</span>, <span class="hljs-number">0</span>)-&gt;<span class="hljs-title function_ invoke__">get</span>();</div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="13"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line">        <span class="hljs-keyword">return</span> <span class="hljs-title function_ invoke__">view</span>(<span class="hljs-string">'admin.category.add'</span>, [<span class="hljs-string">'category'</span> =&gt; <span class="hljs-variable">$category</span>] );</div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="14"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line">    }</div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="15"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line">}</div></div></li></ol></code><div class="hljs-button {2}" data-title="复制" onclick="hljs.copyCode(event)"></div></pre> 
<p>（3）创建<strong>admin\category\add.blade.php</strong>视图文件，具体代码如下：</p> 
<pre data-index="58" class="set-code-show" name="code"><code class="language-php hljs"><ol class="hljs-ln" style="width:100%"><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="1"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line">@<span class="hljs-keyword">extends</span>(<span class="hljs-string">'admin/layouts/admin'</span>)</div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="2"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line">@<span class="hljs-title function_ invoke__">section</span>(<span class="hljs-string">'title'</span>, <span class="hljs-string">' 添加栏目'</span>)</div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="3"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line">@<span class="hljs-title function_ invoke__">section</span>(<span class="hljs-string">'main'</span>)</div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="4"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line">&lt;div <span class="hljs-class"><span class="hljs-class"><span class="hljs-keyword">class</span>="<span class="hljs-title">main</span>-<span class="hljs-title">title</span>"&gt;&lt;<span class="hljs-title">h2</span>&gt;添加栏目&lt;/<span class="hljs-title">h2</span>&gt;&lt;/<span class="hljs-title">div</span>&gt;</span></span></div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="5"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line"><span class="hljs-class">&lt;<span class="hljs-title">div</span> <span class="hljs-title">class</span>="<span class="hljs-title">main</span>-<span class="hljs-title">section</span>"&gt;</span></div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="6"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line"><span class="hljs-class">  &lt;<span class="hljs-title">div</span> <span class="hljs-title">style</span>="<span class="hljs-title">width</span>:543<span class="hljs-title">px</span>"&gt;</span></div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="7"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line"><span class="hljs-class">    &lt;!-- 添加栏目表单 --&gt;</span></div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="8"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line"><span class="hljs-class">    &lt;<span class="hljs-title">form</span> <span class="hljs-title">method</span>="<span class="hljs-title">post</span>" <span class="hljs-title">action</span>="</span>{{ <span class="hljs-title function_ invoke__">url</span>(<span class="hljs-string">'/category/save'</span>) }}<span class="hljs-string"><span class="hljs-string">"&gt;</span></span></div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="9"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line"><span class="hljs-string">      &lt;div class="</span>form-group row<span class="hljs-string"><span class="hljs-string">"&gt;</span></span></div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="10"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line"><span class="hljs-string">        &lt;label class="</span>col-sm-<span class="hljs-number">2</span> col-form-label<span class="hljs-string"><span class="hljs-string">"&gt;序号&lt;/label&gt;</span></span></div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="11"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line"><span class="hljs-string">        &lt;div class="</span>col-sm-<span class="hljs-number">10</span><span class="hljs-string"><span class="hljs-string">"&gt;</span></span></div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="12"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line"><span class="hljs-string">          &lt;input type="</span>number<span class="hljs-string">" name="</span>sort<span class="hljs-string">" class="</span>form-control<span class="hljs-string">" value="</span><span class="hljs-number">0</span><span class="hljs-string">" style="</span>width:<span class="hljs-number">80</span>px;<span class="hljs-string"><span class="hljs-string">"&gt;</span></span></div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="13"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line"><span class="hljs-string">        &lt;/div&gt;</span></div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="14"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line"><span class="hljs-string">      &lt;/div&gt;</span></div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="15"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line"><span class="hljs-string">      &lt;div class="</span>form-group row<span class="hljs-string"><span class="hljs-string">"&gt;</span></span></div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="16"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line"><span class="hljs-string">        &lt;label class="</span>col-sm-<span class="hljs-number">2</span> col-form-label<span class="hljs-string"><span class="hljs-string">"&gt;上级栏目&lt;/label&gt;</span></span></div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="17"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line"><span class="hljs-string">        &lt;div class="</span>col-sm-<span class="hljs-number">10</span><span class="hljs-string"><span class="hljs-string">"&gt;</span></span></div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="18"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line"><span class="hljs-string">          &lt;select name="</span>pid<span class="hljs-string">" class="</span>form-control<span class="hljs-string">" style="</span>width:<span class="hljs-number">200</span>px;<span class="hljs-string"><span class="hljs-string">"&gt;</span></span></div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="19"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line"><span class="hljs-string">            &lt;option value="</span><span class="hljs-number">0</span><span class="hljs-string"><span class="hljs-string">"&gt;---&lt;/option&gt;</span></span></div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="20"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line"><span class="hljs-string">            @foreach (<span class="hljs-subst">$category</span> as <span class="hljs-subst">$v</span>)</span></div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="21"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line"><span class="hljs-string">              &lt;option value="</span>{{ <span class="hljs-variable">$v</span>-&gt;id }}<span class="hljs-string"><span class="hljs-string">"&gt; {{ <span class="hljs-subst">$v</span>-&gt;name }}&lt;/option&gt;</span></span></div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="22"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line"><span class="hljs-string">            @endforeach</span></div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="23"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line"><span class="hljs-string">          &lt;/select&gt;</span></div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="24"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line"><span class="hljs-string">        &lt;/div&gt;</span></div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="25"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line"><span class="hljs-string">      &lt;/div&gt;</span></div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="26"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line"><span class="hljs-string">      &lt;div class="</span>form-group row<span class="hljs-string"><span class="hljs-string">"&gt;</span></span></div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="27"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line"><span class="hljs-string">        &lt;label class="</span>col-sm-<span class="hljs-number">2</span> col-form-label<span class="hljs-string"><span class="hljs-string">"&gt;名称&lt;/label&gt;</span></span></div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="28"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line"><span class="hljs-string">        &lt;div class="</span>col-sm-<span class="hljs-number">10</span><span class="hljs-string"><span class="hljs-string">"&gt;</span></span></div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="29"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line"><span class="hljs-string">          &lt;input type="</span>text<span class="hljs-string">" name="</span>name<span class="hljs-string">" class="</span>form-control<span class="hljs-string">" style="</span>width:<span class="hljs-number">200</span>px;<span class="hljs-string"><span class="hljs-string">"&gt;</span></span></div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="30"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line"><span class="hljs-string">        &lt;/div&gt;</span></div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="31"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line"><span class="hljs-string">      &lt;/div&gt;</span></div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="32"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line"><span class="hljs-string">      &lt;div class="</span>form-group row<span class="hljs-string"><span class="hljs-string">"&gt;</span></span></div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="33"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line"><span class="hljs-string">        &lt;div class="</span>col-sm-<span class="hljs-number">10</span><span class="hljs-string"><span class="hljs-string">"&gt;</span></span></div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="34"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line"><span class="hljs-string">          {{csrf_field()}}</span></div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="35"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line"><span class="hljs-string">          &lt;button type="</span>submit<span class="hljs-string">" class="</span>btn btn-primary mr-<span class="hljs-number">2</span><span class="hljs-string"><span class="hljs-string">"&gt;提交表单&lt;/button&gt;</span></span></div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="36"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line"><span class="hljs-string">          &lt;a href="</span>{{<span class="hljs-title function_ invoke__">url</span>(<span class="hljs-string">'category'</span>)}}<span class="hljs-string">" class="</span>btn btn-secondary<span class="hljs-string"><span class="hljs-string">"&gt;返回列表&lt;/a&gt;</span></span></div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="37"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line"><span class="hljs-string">        &lt;/div&gt;</span></div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="38"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line"><span class="hljs-string">      &lt;/div&gt;</span></div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="39"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line"><span class="hljs-string">    &lt;/form&gt;</span></div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="40"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line"><span class="hljs-string">  &lt;/div&gt;</span></div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="41"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line"><span class="hljs-string">&lt;/div&gt;</span></div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="42"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line"><span class="hljs-string">&lt;script&gt;</span></div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="43"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line"><span class="hljs-string">  main.menuActive('addcategory');</span></div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="44"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line"><span class="hljs-string">&lt;/script&gt;</span></div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="45"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line"><span class="hljs-string">@endsection</span></div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="46"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line"><span class="hljs-string"></span></div></div></li></ol></code><div class="hljs-button {2}" data-title="复制" onclick="hljs.copyCode(event)"></div></pre> 
<p>（4）在<strong>routes\web.php</strong>文件中添加路由规则，具体代码如下：</p> 
<pre data-index="59" class="set-code-show" name="code"><code class="language-php hljs"><ol class="hljs-ln" style="width:100%"><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="1"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line"><span class="hljs-comment">// 栏目</span></div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="2"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line"><span class="hljs-title class_">Route</span>::<span class="hljs-title function_ invoke__">prefix</span>(<span class="hljs-string">'category'</span>)-&gt;<span class="hljs-title function_ invoke__">namespace</span>(<span class="hljs-string">'Admin'</span>)-&gt;<span class="hljs-title function_ invoke__">middleware</span>([<span class="hljs-string">'Admin'</span>])-&gt;<span class="hljs-title function_ invoke__">group</span>(function () {</div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="3"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line">    <span class="hljs-title class_">Route</span>::<span class="hljs-title function_ invoke__">get</span>(<span class="hljs-string">'add'</span>, <span class="hljs-string">'CategoryController@add'</span>);</div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="4"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line">});</div></div></li></ol></code><div class="hljs-button {2}" data-title="复制" onclick="hljs.copyCode(event)"></div></pre> 
<p>（5）修改布局文件<strong>admin.blade.php</strong>,为添加栏目的导航添加链接，具体代码如下：</p> 
<pre data-index="60" class="set-code-show" name="code"><code class="language-php hljs">&lt;a href=<span class="hljs-string">"{{ url('category/add') }}"</span> data-name=<span class="hljs-string">"addcategory"</span>&gt;&lt;i <span class="hljs-class"><span class="hljs-keyword">class</span>="<span class="hljs-title">fa</span> <span class="hljs-title">fa</span>-<span class="hljs-title">list</span> <span class="hljs-title">fa</span>-<span class="hljs-title">fw</span>"&gt;&lt;/<span class="hljs-title">i</span>&gt;添加&lt;/<span class="hljs-title">a</span>&gt;</span></code><div class="hljs-button {2}" data-title="复制" onclick="hljs.copyCode(event)"></div></pre> 
<p>（6）在<strong>Category</strong>控制器中编写<strong>save()</strong>方法，用于接收添加栏目的表单数据，具体代码如下：</p> 
<pre data-index="61" class="set-code-show" name="code"><code class="language-php hljs"><ol class="hljs-ln" style="width:100%"><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="1"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line"> <span class="hljs-keyword">public</span> <span class="hljs-function"><span class="hljs-keyword">function</span> <span class="hljs-title">save</span>(<span class="hljs-params">Request <span class="hljs-variable">$request</span></span>)</span>{</div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="2"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line">        <span class="hljs-variable">$data</span> = <span class="hljs-variable">$request</span>-&gt;<span class="hljs-title function_ invoke__">all</span>();</div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="3"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line">        <span class="hljs-variable language_">$this</span>-&gt;<span class="hljs-title function_ invoke__">validate</span>(<span class="hljs-variable">$request</span>,[</div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="4"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line">            <span class="hljs-string">'name'</span>=&gt;<span class="hljs-string">'required|unique:category'</span>.<span class="hljs-variable">$rule</span>,</div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="5"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line">        ],[</div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="6"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line">            <span class="hljs-string">'name.required'</span>=&gt;<span class="hljs-string">'栏目名称不能为空'</span>,</div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="7"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line">            <span class="hljs-string">'name.unique'</span>=&gt;<span class="hljs-string">'栏目名称不能重复'</span></div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="8"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line">        ]);</div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="9"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line">        <span class="hljs-variable">$re</span> = <span class="hljs-title class_">Category</span>::<span class="hljs-title function_ invoke__">create</span>(<span class="hljs-variable">$data</span>);</div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="10"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line">        <span class="hljs-keyword">if</span>(<span class="hljs-variable">$re</span>){</div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="11"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line">            <span class="hljs-keyword">return</span> <span class="hljs-title function_ invoke__">redirect</span>(<span class="hljs-string">'category'</span>)-&gt;<span class="hljs-title function_ invoke__">with</span>(<span class="hljs-string">'message'</span>,<span class="hljs-string">'添加成功'</span>);</div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="12"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line">        }<span class="hljs-keyword">else</span>{</div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="13"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line">            <span class="hljs-keyword">return</span> <span class="hljs-title function_ invoke__">redirect</span>(<span class="hljs-string">'category/add'</span>)-&gt;<span class="hljs-title function_ invoke__">with</span>(<span class="hljs-string">'tip'</span>,<span class="hljs-string">'添加失败'</span>);</div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="14"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line">        }</div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="15"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line">    }</div></div></li></ol></code><div class="hljs-button {2}" data-title="复制" onclick="hljs.copyCode(event)"></div></pre> 
<p>（7）在<strong>routes\web.php</strong>文件中栏目的路由组中添加路由规则，具体代码如下：</p> 
<pre data-index="62" class="set-code-show" name="code"><code class="language-php hljs"><span class="hljs-title class_">Route</span>::<span class="hljs-title function_ invoke__">post</span>(<span class="hljs-string">'save'</span>, <span class="hljs-string">'CategoryController@save'</span>);</code><div class="hljs-button {2}" data-title="复制" onclick="hljs.copyCode(event)"></div></pre> 
<h4 id="3.%E6%98%BE%E7%A4%BA%E6%A0%8F%E7%9B%AE%E5%88%97%E8%A1%A8"><a name="t17"></a>3.显示栏目列表</h4> 
<p>（1）在<strong>Category</strong>控制器中创建<strong>index()</strong>方法，具体代码如下：</p> 
<pre data-index="63" class="set-code-show" name="code"><code class="language-php hljs"><ol class="hljs-ln" style="width:100%"><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="1"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line">    <span class="hljs-keyword">public</span> <span class="hljs-function"><span class="hljs-keyword">function</span> <span class="hljs-title">index</span>(<span class="hljs-params"></span>)</span>{</div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="2"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line">        <span class="hljs-variable">$category</span> = <span class="hljs-variable language_">$this</span>-&gt;<span class="hljs-title function_ invoke__">getTreeListCheckLeaf</span>(<span class="hljs-variable">$data</span>);</div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="3"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line">        <span class="hljs-keyword">return</span> <span class="hljs-title function_ invoke__">view</span>(<span class="hljs-string">'admin.category.index'</span>, [<span class="hljs-string">'category'</span> =&gt; <span class="hljs-variable">$category</span>]);</div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="4"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line">    }</div></div></li></ol></code><div class="hljs-button {2}" data-title="复制" onclick="hljs.copyCode(event)"></div></pre> 
<p>（2）在<strong>Category</strong>模型中添加<strong>getTreeListCheckLeaf()</strong>方法和<strong>treeList()</strong>方法，具体代码如下：</p> 
<pre data-index="64" class="set-code-show" name="code"><code class="language-php hljs"><ol class="hljs-ln" style="width:100%"><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="1"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line"> <span class="hljs-keyword">public</span> <span class="hljs-function"><span class="hljs-keyword">function</span> <span class="hljs-title">getTreeListCheckLeaf</span>(<span class="hljs-params"><span class="hljs-variable">$data</span>, <span class="hljs-variable">$name</span> = <span class="hljs-string">'isLeaf'</span></span>)</span></div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="2"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line">    {</div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="3"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line">        <span class="hljs-variable">$data</span> = <span class="hljs-variable language_">$this</span>-&gt;<span class="hljs-title function_ invoke__">treeList</span>(<span class="hljs-variable">$data</span>);</div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="4"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line">        <span class="hljs-keyword">foreach</span> (<span class="hljs-variable">$data</span> <span class="hljs-keyword">as</span> <span class="hljs-variable">$k</span> =&gt; <span class="hljs-variable">$v</span>) {</div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="5"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line">            <span class="hljs-keyword">foreach</span> (<span class="hljs-variable">$data</span> <span class="hljs-keyword">as</span> <span class="hljs-variable">$vv</span>) {</div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="6"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line">                <span class="hljs-variable">$data</span>[<span class="hljs-variable">$k</span>][<span class="hljs-variable">$name</span>] = <span class="hljs-literal">true</span>;</div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="7"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line">                <span class="hljs-keyword">if</span> (<span class="hljs-variable">$v</span>[<span class="hljs-string">'id'</span>] === <span class="hljs-variable">$vv</span>[<span class="hljs-string">'pid'</span>]) {</div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="8"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line">                    <span class="hljs-variable">$data</span>[<span class="hljs-variable">$k</span>][<span class="hljs-variable">$name</span>] = <span class="hljs-literal">false</span>;</div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="9"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line">                    <span class="hljs-keyword">break</span>;</div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="10"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line">                }</div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="11"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line">            }</div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="12"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line">        }</div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="13"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line">        <span class="hljs-keyword">return</span> <span class="hljs-variable">$data</span>;</div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="14"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line">    }</div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="15"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line"> </div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="16"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line">    <span class="hljs-keyword">public</span> <span class="hljs-function"><span class="hljs-keyword">function</span> <span class="hljs-title">treeList</span>(<span class="hljs-params"><span class="hljs-variable">$data</span>, <span class="hljs-variable">$pid</span> = <span class="hljs-number">0</span>, <span class="hljs-variable">$level</span> = <span class="hljs-number">0</span>, &amp;<span class="hljs-variable">$tree</span> = []</span>)</span></div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="17"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line">    {</div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="18"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line">        <span class="hljs-keyword">foreach</span> (<span class="hljs-variable">$data</span> <span class="hljs-keyword">as</span> <span class="hljs-variable">$v</span>) {</div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="19"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line">            <span class="hljs-keyword">if</span> (<span class="hljs-variable">$v</span>[<span class="hljs-string">'pid'</span>] == <span class="hljs-variable">$pid</span>) {</div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="20"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line">                <span class="hljs-variable">$v</span>[<span class="hljs-string">'level'</span>] = <span class="hljs-variable">$level</span>;</div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="21"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line">                <span class="hljs-variable">$tree</span>[] = <span class="hljs-variable">$v</span>;</div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="22"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line">                <span class="hljs-variable language_">$this</span>-&gt;<span class="hljs-title function_ invoke__">treeList</span>(<span class="hljs-variable">$data</span>, <span class="hljs-variable">$v</span>[<span class="hljs-string">'id'</span>], <span class="hljs-variable">$level</span> + <span class="hljs-number">1</span>, <span class="hljs-variable">$tree</span>);</div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="23"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line">            }</div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="24"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line">        }</div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="25"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line">        <span class="hljs-keyword">return</span> <span class="hljs-variable">$tree</span>;</div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="26"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line">    }</div></div></li></ol></code><div class="hljs-button {2}" data-title="复制" onclick="hljs.copyCode(event)"></div></pre> 
<p>（3）创建视图文件<strong>index.php</strong>,具体代码如下：</p> 
<pre data-index="65" class="set-code-show" name="code"><code class="language-php hljs"><ol class="hljs-ln" style="width:1491px"><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="1"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line">@<span class="hljs-keyword">extends</span>(<span class="hljs-string">'admin/layouts/admin'</span>)</div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="2"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line">@<span class="hljs-title function_ invoke__">section</span>(<span class="hljs-string">'title'</span>, <span class="hljs-string">'栏目列表'</span>)</div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="3"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line">@<span class="hljs-title function_ invoke__">section</span>(<span class="hljs-string">'main'</span>)</div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="4"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line">&lt;div <span class="hljs-class"><span class="hljs-class"><span class="hljs-keyword">class</span>="<span class="hljs-title">main</span>-<span class="hljs-title">title</span>"&gt;&lt;<span class="hljs-title">h2</span>&gt;栏目管理&lt;/<span class="hljs-title">h2</span>&gt;&lt;/<span class="hljs-title">div</span>&gt;</span></span></div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="5"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line"><span class="hljs-class">&lt;<span class="hljs-title">div</span> <span class="hljs-title">class</span>="<span class="hljs-title">main</span>-<span class="hljs-title">section</span> <span class="hljs-title">form</span>-<span class="hljs-title">inline</span>"&gt;</span></div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="6"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line"><span class="hljs-class">  &lt;<span class="hljs-title">a</span> <span class="hljs-title">href</span>="</span>{{ <span class="hljs-title function_ invoke__">url</span>(<span class="hljs-string">'category/add'</span>) }}<span class="hljs-string">" class="</span>btn btn-success<span class="hljs-string"><span class="hljs-string">"&gt;+ 新增&lt;/a&gt;</span></span></div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="7"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line"><span class="hljs-string">&lt;/div&gt;</span></div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="8"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line"><span class="hljs-string">&lt;div class="</span>main-section<span class="hljs-string"><span class="hljs-string">"&gt;</span></span></div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="9"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line"><span class="hljs-string">  &lt;form method="</span>post<span class="hljs-string">" action="</span><span class="hljs-string">" class="</span>j-form<span class="hljs-string"><span class="hljs-string">"&gt;</span></span></div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="10"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line"><span class="hljs-string">    &lt;table class="</span>table table-striped table-bordered table-hover<span class="hljs-string"><span class="hljs-string">"&gt;</span></span></div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="11"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line"><span class="hljs-string">      &lt;thead&gt;</span></div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="12"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line"><span class="hljs-string">      &lt;tr&gt;</span></div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="13"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line"><span class="hljs-string">        &lt;th width="</span><span class="hljs-number">75</span><span class="hljs-string">"&gt;序号&lt;/th&gt;&lt;th&gt;名称&lt;/th&gt;&lt;th width="</span><span class="hljs-number">100</span><span class="hljs-string"><span class="hljs-string">"&gt;操作&lt;/th&gt;</span></span></div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="14"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line"><span class="hljs-string">      &lt;/tr&gt;</span></div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="15"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line"><span class="hljs-string">      &lt;/thead&gt;</span></div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="16"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line"><span class="hljs-string">      &lt;tbody&gt;</span></div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="17"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line"><span class="hljs-string">      &lt;!-- 栏目列表 --&gt;</span></div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="18"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line"><span class="hljs-string">      @foreach(<span class="hljs-subst">$category</span>)</span></div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="19"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line"><span class="hljs-string">        &lt;tr class="</span>j-pid-{{ <span class="hljs-variable">$v</span>[<span class="hljs-string">'pid'</span>] }}<span class="hljs-string"><span class="hljs-string">"</span></span></div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="20"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line"><span class="hljs-string">          @if(<span class="hljs-subst">$v</span>['level'])style="</span>display:none<span class="hljs-string"><span class="hljs-string">"@endif&gt;</span></span></div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="21"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line"><span class="hljs-string">          &lt;td&gt;&lt;input type="</span>text<span class="hljs-string">" class="</span>form-control j-sort<span class="hljs-string">" maxlength="</span><span class="hljs-number">5</span><span class="hljs-string">" value="</span>{{<span class="hljs-variable">$v</span>[<span class="hljs-string">'sort'</span>]}}<span class="hljs-string">" data-name="</span>sort[{{<span class="hljs-variable">$v</span>[<span class="hljs-string">'id'</span>]}}]<span class="hljs-string">" style="</span>height:<span class="hljs-number">25</span>px;font-size:<span class="hljs-number">12</span>px;padding:<span class="hljs-number">0</span> <span class="hljs-number">5</span>px;<span class="hljs-string"><span class="hljs-string">"&gt;&lt;/td&gt;</span></span></div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="22"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line"><span class="hljs-string">          &lt;td&gt;</span></div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="23"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line"><span class="hljs-string">            @if(<span class="hljs-subst">$v</span>['level'])</span></div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="24"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line"><span class="hljs-string">              &lt;small class="</span>text-muted<span class="hljs-string"><span class="hljs-string">"&gt;├──&lt;/small&gt; {<span class="hljs-subst">{$v['name']}</span>}</span></span></div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="25"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line"><span class="hljs-string">            @else</span></div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="26"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line"><span class="hljs-string">              &lt;a href="</span><span class="hljs-comment">#" class="j-toggle" data-id="{{$v['id']}}"&gt;</span></div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="27"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line">                @<span class="hljs-keyword">if</span>(!<span class="hljs-variable">$v</span>[<span class="hljs-string">'isLeaf'</span>])</div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="28"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line">                  &lt;i <span class="hljs-class"><span class="hljs-class"><span class="hljs-keyword">class</span>="<span class="hljs-title">fa</span> <span class="hljs-title">fa</span>-<span class="hljs-title">plus</span>-<span class="hljs-title">square</span>-<span class="hljs-title">o</span> <span class="hljs-title">fa</span>-<span class="hljs-title">minus</span>-<span class="hljs-title">square</span>-<span class="hljs-title">o</span> <span class="hljs-title">fa</span>-<span class="hljs-title">fw</span>"&gt;&lt;/<span class="hljs-title">i</span>&gt;</span></span></div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="29"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line"><span class="hljs-class">                @<span class="hljs-title">endif</span></span></div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="30"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line"><span class="hljs-class">                </span>{{<span class="hljs-variable">$v</span>[<span class="hljs-string">'name'</span>]}}</div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="31"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line">              &lt;/a&gt;</div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="32"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line">            @<span class="hljs-keyword">endif</span></div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="33"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line">          &lt;/td&gt;</div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="34"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line">          &lt;td&gt;</div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="35"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line">            &lt;a href=<span class="hljs-string">"{{ url('category/edit', ['id' =&gt; <span class="hljs-subst">$v</span>['id']]) }}"</span> style=<span class="hljs-string">"margin-right:5px;"</span>&gt;编辑&lt;/a&gt;</div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="36"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line">            &lt;a href=<span class="hljs-string">"{{ url('category/delete', ['id' =&gt; <span class="hljs-subst">$v</span>['id']]) }}"</span> <span class="hljs-class"><span class="hljs-class"><span class="hljs-keyword">class</span>="<span class="hljs-title">j</span>-<span class="hljs-title">del</span> <span class="hljs-title">text</span>-<span class="hljs-title">danger</span>"&gt;删除&lt;/<span class="hljs-title">a</span>&gt;</span></span></div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="37"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line"><span class="hljs-class">          &lt;/<span class="hljs-title">td</span>&gt;</span></div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="38"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line"><span class="hljs-class">        &lt;/<span class="hljs-title">tr</span>&gt;</span></div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="39"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line"><span class="hljs-class">      @<span class="hljs-title">endforeach</span></span></div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="40"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line"><span class="hljs-class">      @<span class="hljs-title">if</span>(<span class="hljs-title">empty</span>($<span class="hljs-title">category</span>))</span></div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="41"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line"><span class="hljs-class">        &lt;<span class="hljs-title">tr</span>&gt;&lt;<span class="hljs-title">td</span> <span class="hljs-title">colspan</span>="4" <span class="hljs-title">class</span>="<span class="hljs-title">text</span>-<span class="hljs-title">center</span>"&gt;还没有添加栏目&lt;/<span class="hljs-title">td</span>&gt;&lt;/<span class="hljs-title">tr</span>&gt;</span></div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="42"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line"><span class="hljs-class">      @<span class="hljs-title">endif</span></span></div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="43"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line"><span class="hljs-class">      &lt;/<span class="hljs-title">tbody</span>&gt;</span></div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="44"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line"><span class="hljs-class">    &lt;/<span class="hljs-title">table</span>&gt;</span></div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="45"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line"><span class="hljs-class">    </span>{{<span class="hljs-title function_ invoke__">csrf_field</span>()}}</div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="46"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line">    &lt;input type=<span class="hljs-string">"submit"</span> value=<span class="hljs-string">"改变排序"</span> <span class="hljs-class"><span class="hljs-class"><span class="hljs-keyword">class</span>="<span class="hljs-title">btn</span> <span class="hljs-title">btn</span>-<span class="hljs-title">primary</span>"&gt;</span></span></div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="47"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line"><span class="hljs-class">  &lt;/<span class="hljs-title">form</span>&gt;</span></div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="48"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line"><span class="hljs-class">&lt;/<span class="hljs-title">div</span>&gt;</span></div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="49"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line"><span class="hljs-class">&lt;<span class="hljs-title">script</span>&gt;</span></div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="50"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line"><span class="hljs-class">  <span class="hljs-title">main</span>.<span class="hljs-title">menuActive</span>('<span class="hljs-title">category</span>');</span></div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="51"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line"><span class="hljs-class">  $('.<span class="hljs-title">j</span>-<span class="hljs-title">toggle</span>').<span class="hljs-title">click</span>(<span class="hljs-title">function</span>() </span>{</div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="52"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line">    <span class="hljs-keyword">var</span> id = $(this).<span class="hljs-title function_ invoke__">attr</span>(<span class="hljs-string">'data-id'</span>);</div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="53"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line">    $(this).<span class="hljs-title function_ invoke__">find</span>(<span class="hljs-string">'i'</span>).<span class="hljs-title function_ invoke__">toggleClass</span>(<span class="hljs-string">'fa-plus-square-o'</span>);</div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="54"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line">    $(<span class="hljs-string">'.j-pid-'</span> + id).<span class="hljs-title function_ invoke__">toggle</span>();</div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="55"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line">    <span class="hljs-keyword">return</span> <span class="hljs-literal">false</span>;</div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="56"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line">  });</div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="57"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line">  $(<span class="hljs-string">'.j-sort'</span>).<span class="hljs-title function_ invoke__">change</span>(function() {</div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="58"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line">    $(this).<span class="hljs-title function_ invoke__">attr</span>(<span class="hljs-string">'name'</span>, $(this).<span class="hljs-title function_ invoke__">attr</span>(<span class="hljs-string">'data-name'</span>));</div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="59"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line">  });</div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="60"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line">  $(<span class="hljs-string">'.j-del'</span>).<span class="hljs-title function_ invoke__">click</span>(function() {</div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="61"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line">    <span class="hljs-keyword">if</span> (<span class="hljs-title function_ invoke__">confirm</span>(<span class="hljs-string">'您确定要删除此项？'</span>)) {</div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="62"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line">      <span class="hljs-keyword">var</span> data = { _token: <span class="hljs-string">'{{ csrf_token() }}'</span> };</div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="63"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line">      main.<span class="hljs-title function_ invoke__">ajaxPost</span>({<span class="hljs-attr">url</span>:$(this).<span class="hljs-title function_ invoke__">attr</span>(<span class="hljs-string">'href'</span>), data: data}, <span class="hljs-function"><span class="hljs-keyword">function</span>(<span class="hljs-params"></span>)</span>{</div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="64"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line">        location.<span class="hljs-title function_ invoke__">reload</span>();</div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="65"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line">      });</div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="66"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line">    }</div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="67"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line">    <span class="hljs-keyword">return</span> <span class="hljs-literal">false</span>;</div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="68"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line">  });</div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="69"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line">&lt;/script&gt;</div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="70"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line">@endsection</div></div></li></ol></code><div class="hljs-button {2}" data-title="复制" onclick="hljs.copyCode(event)"></div></pre> 
<p>（4）在<strong>routes\web.php</strong>文件中栏目的路由组中添加栏目列表的路由规则，具体代码如下：</p> 
<pre data-index="66" class="set-code-show" name="code"><code class="language-php hljs">    <span class="hljs-title class_">Route</span>::<span class="hljs-title function_ invoke__">get</span>(<span class="hljs-string">''</span>, <span class="hljs-string">'CategoryController@index'</span>);
</code><div class="hljs-button {2}" data-title="复制" onclick="hljs.copyCode(event)"></div></pre> 
<p>（5）修改<strong>admin.blade.php</strong>,为列表菜单项添加链接，具体代码如下：</p> 
<pre data-index="67" class="set-code-show" name="code"><code class="language-php hljs"><ol class="hljs-ln" style="width:100%"><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="1"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line">&lt;a href=<span class="hljs-string">"{{ url('category') }}"</span> data-name=<span class="hljs-string">"category"</span>&gt;&lt;i <span class="hljs-class"><span class="hljs-keyword">class</span>="<span class="hljs-title">fa</span> <span class="hljs-title">fa</span>-<span class="hljs-title">table</span> <span class="hljs-title">fa</span>-<span class="hljs-title">fw</span>"&gt;&lt;/<span class="hljs-title">i</span>&gt;列表&lt;/<span class="hljs-title">a</span>&gt;</span></div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="2"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line"></div></div></li></ol></code><div class="hljs-button {2}" data-title="复制" onclick="hljs.copyCode(event)"></div></pre> 
<p>（6）通过浏览器访问，栏目列表的页面效果如下图所示：</p> 
<p style="text-align:center;"><img alt="" src="https://img-blog.csdnimg.cn/83fc5bc3176a42459ec5f527ab38b228.png"></p> 
<p>（7） 在栏目列表页中，为了实现修改栏目的排序，需要设置栏目列表页中表单的提交地址，具体代码如下：</p> 
<pre data-index="68" class="set-code-show" name="code"><code class="language-php hljs"><ol class="hljs-ln" style="width:100%"><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="1"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line">  &lt;form method=<span class="hljs-string">"post"</span> action=<span class="hljs-string">"{{ url('category/sort')}}"</span> <span class="hljs-class"><span class="hljs-keyword">class</span>="<span class="hljs-title">j</span>-<span class="hljs-title">form</span>"&gt;</span></div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="2"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line"></div></div></li></ol></code><div class="hljs-button {2}" data-title="复制" onclick="hljs.copyCode(event)"></div></pre> 
<p>（8）在<strong>routes\web.php</strong>文件中栏目的路由组中添加排序的路由规则，具体代码如下：</p> 
<pre data-index="69" class="set-code-show" name="code"><code class="language-php hljs">    <span class="hljs-title class_">Route</span>::<span class="hljs-title function_ invoke__">post</span>(<span class="hljs-string">'sort'</span>, <span class="hljs-string">'CategoryController@sort'</span>);
</code><div class="hljs-button {2}" data-title="复制" onclick="hljs.copyCode(event)"></div></pre> 
<p>（9）在<strong>Category</strong>控制器中添加<strong>sort()</strong>方法，具体代码如下：</p> 
<pre data-index="70" class="set-code-show" name="code"><code class="language-php hljs"><ol class="hljs-ln" style="width:100%"><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="1"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line"><span class="hljs-keyword">public</span> <span class="hljs-function"><span class="hljs-keyword">function</span> <span class="hljs-title">sort</span>(<span class="hljs-params">Request <span class="hljs-variable">$request</span></span>)</span>{</div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="2"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line">        <span class="hljs-variable">$sort</span> = <span class="hljs-variable">$request</span>-&gt;<span class="hljs-title function_ invoke__">input</span>(<span class="hljs-string">'sort'</span>);</div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="3"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line">        <span class="hljs-keyword">foreach</span> (<span class="hljs-variable">$sort</span> <span class="hljs-keyword">as</span> <span class="hljs-variable">$k</span> =&gt; <span class="hljs-variable">$v</span>) {</div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="4"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line">            <span class="hljs-title class_">Category</span>::<span class="hljs-title function_ invoke__">where</span>(<span class="hljs-string">'id'</span>, (<span class="hljs-keyword">int</span>)<span class="hljs-variable">$k</span>)-&gt;<span class="hljs-title function_ invoke__">update</span>([<span class="hljs-string">'sort'</span> =&gt; (<span class="hljs-keyword">int</span>)<span class="hljs-variable">$v</span>]);</div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="5"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line">        }</div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="6"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line">        <span class="hljs-keyword">return</span> <span class="hljs-title function_ invoke__">redirect</span>(<span class="hljs-string">'category'</span>)-&gt;<span class="hljs-title function_ invoke__">with</span>(<span class="hljs-string">'message'</span>,<span class="hljs-string">'改变排序成功'</span>);</div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="7"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line">    }</div></div></li></ol></code><div class="hljs-button {2}" data-title="复制" onclick="hljs.copyCode(event)"></div></pre> 
<p>（10）通过浏览器访问，观察栏目功能是否正确执行。</p> 
<p><img alt="" height="821" src="https://img-blog.csdnimg.cn/527aa3ecdc2f412181951908261a4e78.png" width="1200"></p> 
<h4 id="4.%E7%BC%96%E8%BE%91%E6%A0%8F%E7%9B%AE%C2%A0"><a name="t18"></a>4.编辑栏目&nbsp;</h4> 
<p>（1）在列表页中为“编辑”按钮添加链接，具体代码如下：</p> 
<pre data-index="71" class="set-code-show" name="code"><code class="language-php hljs">&lt;a href=<span class="hljs-string">"{{ url('category/edit', ['id' =&gt; <span class="hljs-subst">$v</span>['id']]) }}"</span> style=<span class="hljs-string">"margin-right:5px;"</span>&gt;编辑&lt;/a&gt;
</code><div class="hljs-button {2}" data-title="复制" onclick="hljs.copyCode(event)"></div></pre> 
<p>（2）在<strong>routes\web.php</strong>文件中栏目的路由组中添加编辑栏目的路由规则，具体代码如下：</p> 
<pre data-index="72" class="set-code-show" name="code"><code class="language-php hljs">    <span class="hljs-title class_">Route</span>::<span class="hljs-title function_ invoke__">get</span>(<span class="hljs-string">'edit/{id}'</span>, <span class="hljs-string">'CategoryController@edit'</span>);
</code><div class="hljs-button {2}" data-title="复制" onclick="hljs.copyCode(event)"></div></pre> 
<p>（3）在<strong>Category</strong>控制器中添加edit()方法，具体代码如下：</p> 
<pre data-index="73" class="set-code-show" name="code"><code class="language-php hljs"><ol class="hljs-ln" style="width:100%"><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="1"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line"><span class="hljs-keyword">public</span> <span class="hljs-function"><span class="hljs-keyword">function</span> <span class="hljs-title">edit</span>(<span class="hljs-params"><span class="hljs-variable">$id</span></span>)</span>{</div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="2"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line">        <span class="hljs-variable">$data</span> = [];</div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="3"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line">        <span class="hljs-keyword">if</span> (<span class="hljs-variable">$id</span>) {</div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="4"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line">            <span class="hljs-keyword">if</span> (!<span class="hljs-variable">$data</span> = <span class="hljs-title class_">Category</span>::<span class="hljs-title function_ invoke__">find</span>(<span class="hljs-variable">$id</span>)) {</div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="5"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line">                <span class="hljs-keyword">return</span> <span class="hljs-title function_ invoke__">back</span>()-&gt;<span class="hljs-title function_ invoke__">with</span>(<span class="hljs-string">'tip'</span>, <span class="hljs-string">'记录不存在。'</span>);</div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="6"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line">            }</div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="7"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line">        }</div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="8"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line">        <span class="hljs-variable">$category</span> = <span class="hljs-title class_">Category</span>::<span class="hljs-title function_ invoke__">where</span>(<span class="hljs-string">'pid'</span>, <span class="hljs-number">0</span>)-&gt;<span class="hljs-title function_ invoke__">get</span>();</div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="9"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line">        <span class="hljs-keyword">return</span> <span class="hljs-title function_ invoke__">view</span>(<span class="hljs-string">'admin.category.edit'</span>, [<span class="hljs-string">'id'</span>=&gt;<span class="hljs-variable">$id</span>, <span class="hljs-string">'data'</span>=&gt;<span class="hljs-variable">$data</span>, <span class="hljs-string">'category'</span> =&gt; <span class="hljs-variable">$category</span>]);</div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="10"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line">    }</div></div></li></ol></code><div class="hljs-button {2}" data-title="复制" onclick="hljs.copyCode(event)"></div></pre> 
<p>（4）创建视图文件<strong>edit.blade.php</strong>,具体代码如下：</p> 
<pre data-index="74" class="set-code-show" name="code"><code class="language-php hljs"><ol class="hljs-ln" style="width:100%"><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="1"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line">@<span class="hljs-keyword">extends</span>(<span class="hljs-string">'admin/layouts/admin'</span>)</div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="2"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line">@<span class="hljs-title function_ invoke__">section</span>(<span class="hljs-string">'title'</span>, <span class="hljs-string">'栏目列表'</span>)</div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="3"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line">@<span class="hljs-title function_ invoke__">section</span>(<span class="hljs-string">'main'</span>)</div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="4"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line">&lt;div <span class="hljs-class"><span class="hljs-class"><span class="hljs-keyword">class</span>="<span class="hljs-title">main</span>-<span class="hljs-title">title</span>"&gt;&lt;<span class="hljs-title">h2</span>&gt;编辑分类&lt;/<span class="hljs-title">h2</span>&gt;&lt;/<span class="hljs-title">div</span>&gt;</span></span></div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="5"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line"><span class="hljs-class">&lt;<span class="hljs-title">div</span> <span class="hljs-title">class</span>="<span class="hljs-title">main</span>-<span class="hljs-title">section</span>"&gt;</span></div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="6"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line"><span class="hljs-class">  &lt;<span class="hljs-title">div</span> <span class="hljs-title">style</span>="<span class="hljs-title">width</span>:543<span class="hljs-title">px</span>"&gt;</span></div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="7"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line"><span class="hljs-class">    &lt;!-- 编辑表单 --&gt;</span></div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="8"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line"><span class="hljs-class">    &lt;<span class="hljs-title">form</span> <span class="hljs-title">method</span>="<span class="hljs-title">post</span>" <span class="hljs-title">action</span>="</span>{{ <span class="hljs-title function_ invoke__">url</span>(<span class="hljs-string">'/category/save'</span>) }}<span class="hljs-string"><span class="hljs-string">"&gt;</span></span></div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="9"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line"><span class="hljs-string">      &lt;div class="</span>form-group row<span class="hljs-string"><span class="hljs-string">"&gt;</span></span></div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="10"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line"><span class="hljs-string">        &lt;label class="</span>col-sm-<span class="hljs-number">2</span> col-form-label<span class="hljs-string"><span class="hljs-string">"&gt;序号&lt;/label&gt;</span></span></div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="11"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line"><span class="hljs-string">        &lt;div class="</span>col-sm-<span class="hljs-number">10</span><span class="hljs-string"><span class="hljs-string">"&gt;</span></span></div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="12"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line"><span class="hljs-string">          &lt;input type="</span>number<span class="hljs-string">" name="</span>sort<span class="hljs-string">" class="</span>form-control<span class="hljs-string">" value="</span>{{<span class="hljs-variable">$data</span>-&gt;sort}}<span class="hljs-string">" style="</span>width:<span class="hljs-number">80</span>px;<span class="hljs-string"><span class="hljs-string">"&gt;</span></span></div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="13"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line"><span class="hljs-string">        &lt;/div&gt;</span></div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="14"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line"><span class="hljs-string">      &lt;/div&gt;</span></div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="15"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line"><span class="hljs-string">      &lt;div class="</span>form-group row<span class="hljs-string"><span class="hljs-string">"&gt;</span></span></div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="16"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line"><span class="hljs-string">        &lt;label class="</span>col-sm-<span class="hljs-number">2</span> col-form-label<span class="hljs-string"><span class="hljs-string">"&gt;上级分类&lt;/label&gt;</span></span></div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="17"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line"><span class="hljs-string">        &lt;div class="</span>col-sm-<span class="hljs-number">10</span><span class="hljs-string"><span class="hljs-string">"&gt;</span></span></div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="18"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line"><span class="hljs-string">          &lt;select name="</span>pid<span class="hljs-string">" class="</span>form-control<span class="hljs-string">" style="</span>width:<span class="hljs-number">200</span>px;<span class="hljs-string"><span class="hljs-string">"&gt;</span></span></div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="19"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line"><span class="hljs-string">            &lt;option value="</span><span class="hljs-number">0</span><span class="hljs-string"><span class="hljs-string">"&gt;---&lt;/option&gt;</span></span></div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="20"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line"><span class="hljs-string">            @foreach(<span class="hljs-subst">$category</span> as <span class="hljs-subst">$v</span>)</span></div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="21"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line"><span class="hljs-string">              &lt;option value="</span>{{ <span class="hljs-variable">$v</span>-&gt;id }}<span class="hljs-string"><span class="hljs-string">" @if(<span class="hljs-subst">$data</span>['pid'] == <span class="hljs-subst">$v</span>['id']) selected @endif&gt; {{ <span class="hljs-subst">$v</span>-&gt;name }}&lt;/option&gt;</span></span></div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="22"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line"><span class="hljs-string">            @endforeach</span></div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="23"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line"><span class="hljs-string">          &lt;/select&gt;</span></div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="24"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line"><span class="hljs-string">        &lt;/div&gt;</span></div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="25"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line"><span class="hljs-string">      &lt;/div&gt;</span></div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="26"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line"><span class="hljs-string">      &lt;div class="</span>form-group row<span class="hljs-string"><span class="hljs-string">"&gt;</span></span></div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="27"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line"><span class="hljs-string">        &lt;label class="</span>col-sm-<span class="hljs-number">2</span> col-form-label<span class="hljs-string"><span class="hljs-string">"&gt;名称&lt;/label&gt;</span></span></div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="28"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line"><span class="hljs-string">        &lt;div class="</span>col-sm-<span class="hljs-number">10</span><span class="hljs-string"><span class="hljs-string">"&gt;</span></span></div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="29"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line"><span class="hljs-string">          &lt;input type="</span>text<span class="hljs-string">" name="</span>name<span class="hljs-string">" class="</span>form-control<span class="hljs-string">" value="</span>{{<span class="hljs-variable">$data</span>-&gt;name}}<span class="hljs-string">" style="</span>width:<span class="hljs-number">200</span>px;<span class="hljs-string"><span class="hljs-string">"&gt;</span></span></div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="30"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line"><span class="hljs-string">        &lt;/div&gt;</span></div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="31"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line"><span class="hljs-string">      &lt;/div&gt;</span></div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="32"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line"><span class="hljs-string">      &lt;div class="</span>form-group row<span class="hljs-string"><span class="hljs-string">"&gt;</span></span></div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="33"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line"><span class="hljs-string">        &lt;div class="</span>col-sm-<span class="hljs-number">10</span><span class="hljs-string"><span class="hljs-string">"&gt;</span></span></div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="34"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line"><span class="hljs-string">          {{csrf_field()}}</span></div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="35"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line"><span class="hljs-string">          &lt;input type="</span>hidden<span class="hljs-string">" name="</span>id<span class="hljs-string">" value="</span>{{<span class="hljs-variable">$id</span>}}<span class="hljs-string"><span class="hljs-string">"&gt;</span></span></div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="36"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line"><span class="hljs-string">          &lt;button type="</span>submit<span class="hljs-string">" class="</span>btn btn-primary mr-<span class="hljs-number">2</span><span class="hljs-string"><span class="hljs-string">"&gt;提交表单&lt;/button&gt;</span></span></div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="37"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line"><span class="hljs-string">          &lt;a href="</span>{{<span class="hljs-title function_ invoke__">url</span>(<span class="hljs-string">'category'</span>)}}<span class="hljs-string">" class="</span>btn btn-secondary<span class="hljs-string"><span class="hljs-string">"&gt;返回列表&lt;/a&gt;</span></span></div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="38"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line"><span class="hljs-string">          {{--&lt;a href="</span>{{<span class="hljs-title function_ invoke__">url</span>(<span class="hljs-string">'category'</span>)}}<span class="hljs-string"><span class="hljs-string">"&gt;--}}</span></span></div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="39"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line"><span class="hljs-string">            {{--&lt;button class="</span>btn btn-secondary<span class="hljs-string"><span class="hljs-string">"&gt;返回列表&lt;/button&gt;--}}</span></span></div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="40"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line"><span class="hljs-string">          {{--&lt;/a&gt;--}}</span></div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="41"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line"><span class="hljs-string">        &lt;/div&gt;</span></div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="42"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line"><span class="hljs-string">      &lt;/div&gt;</span></div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="43"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line"><span class="hljs-string">    &lt;/form&gt;</span></div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="44"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line"><span class="hljs-string">  &lt;/div&gt;</span></div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="45"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line"><span class="hljs-string">&lt;/div&gt;</span></div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="46"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line"><span class="hljs-string">&lt;script&gt;</span></div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="47"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line"><span class="hljs-string">  main.menuActive('category');</span></div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="48"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line"><span class="hljs-string">&lt;/script&gt;</span></div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="49"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line"><span class="hljs-string">@endsection</span></div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="50"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line"><span class="hljs-string"></span></div></div></li></ol></code><div class="hljs-button {2}" data-title="复制" onclick="hljs.copyCode(event)"></div></pre> 
<p>（5）修改<strong>save()</strong>方法，根据栏目id更新栏目内容，具体代码如下：</p> 
<pre data-index="75" class="set-code-show" name="code"><code class="language-php hljs"><ol class="hljs-ln" style="width:100%"><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="1"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line"><span class="hljs-keyword">public</span> <span class="hljs-function"><span class="hljs-keyword">function</span> <span class="hljs-title">save</span>(<span class="hljs-params">Request <span class="hljs-variable">$request</span></span>)</span>{</div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="2"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line">        <span class="hljs-variable">$data</span> = <span class="hljs-variable">$request</span>-&gt;<span class="hljs-title function_ invoke__">all</span>();</div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="3"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line">        <span class="hljs-variable">$rule</span> = <span class="hljs-keyword">isset</span>(<span class="hljs-variable">$data</span>[<span class="hljs-string">'id'</span>]) ? <span class="hljs-string">',name,'</span>.<span class="hljs-variable">$data</span>[<span class="hljs-string">'id'</span>] : <span class="hljs-string">''</span>;</div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="4"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line">        <span class="hljs-variable language_">$this</span>-&gt;<span class="hljs-title function_ invoke__">validate</span>(<span class="hljs-variable">$request</span>,[</div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="5"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line">            <span class="hljs-string">'name'</span>=&gt;<span class="hljs-string">'required|unique:category'</span>.<span class="hljs-variable">$rule</span>,</div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="6"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line">        ],[</div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="7"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line">            <span class="hljs-string">'name.required'</span>=&gt;<span class="hljs-string">'栏目名称不能为空'</span>,</div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="8"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line">            <span class="hljs-string">'name.unique'</span>=&gt;<span class="hljs-string">'栏目名称不能重复'</span></div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="9"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line">        ]);</div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="10"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line">        <span class="hljs-keyword">if</span>(<span class="hljs-keyword">isset</span>(<span class="hljs-variable">$data</span>[<span class="hljs-string">'id'</span>])){</div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="11"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line">            <span class="hljs-variable">$id</span> = <span class="hljs-variable">$data</span>[<span class="hljs-string">'id'</span>];</div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="12"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line">            <span class="hljs-keyword">unset</span>(<span class="hljs-variable">$data</span>[<span class="hljs-string">'id'</span>]);</div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="13"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line">            <span class="hljs-keyword">unset</span>(<span class="hljs-variable">$data</span>[<span class="hljs-string">'_token'</span>]);</div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="14"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line">            <span class="hljs-variable">$res</span> = <span class="hljs-title class_">Category</span>::<span class="hljs-title function_ invoke__">where</span>(<span class="hljs-string">'id'</span>,<span class="hljs-variable">$id</span>)-&gt;<span class="hljs-title function_ invoke__">update</span>(<span class="hljs-variable">$data</span>);</div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="15"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line">            <span class="hljs-variable">$type</span> = <span class="hljs-variable">$res</span> ? <span class="hljs-string">"message"</span> : <span class="hljs-string">"tip"</span>;</div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="16"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line">            <span class="hljs-variable">$message</span> = <span class="hljs-variable">$res</span> ? <span class="hljs-string">"修改成功"</span> : <span class="hljs-string">"修改失败"</span>;</div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="17"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line">            <span class="hljs-keyword">return</span> <span class="hljs-title function_ invoke__">redirect</span>(<span class="hljs-string">'category'</span>)-&gt;<span class="hljs-title function_ invoke__">with</span>(<span class="hljs-variable">$type</span>, <span class="hljs-variable">$message</span>);</div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="18"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line">        }</div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="19"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line">        <span class="hljs-variable">$re</span> = <span class="hljs-title class_">Category</span>::<span class="hljs-title function_ invoke__">create</span>(<span class="hljs-variable">$data</span>);</div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="20"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line">        <span class="hljs-keyword">if</span>(<span class="hljs-variable">$re</span>){</div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="21"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line">            <span class="hljs-keyword">return</span> <span class="hljs-title function_ invoke__">redirect</span>(<span class="hljs-string">'category'</span>)-&gt;<span class="hljs-title function_ invoke__">with</span>(<span class="hljs-string">'message'</span>,<span class="hljs-string">'添加成功'</span>);</div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="22"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line">        }<span class="hljs-keyword">else</span>{</div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="23"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line">            <span class="hljs-keyword">return</span> <span class="hljs-title function_ invoke__">redirect</span>(<span class="hljs-string">'category/add'</span>)-&gt;<span class="hljs-title function_ invoke__">with</span>(<span class="hljs-string">'tip'</span>,<span class="hljs-string">'添加失败'</span>);</div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="24"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line">        }</div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="25"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line">    }</div></div></li></ol></code><div class="hljs-button {2}" data-title="复制" onclick="hljs.copyCode(event)"></div></pre> 
<h4 id="5.%E5%88%A0%E9%99%A4%E6%A0%8F%E7%9B%AE"><a name="t19"></a>5.删除栏目</h4> 
<p>（1）在列表页中为“删除”按钮添加链接，具体代码如下：</p> 
<pre data-index="76" class="set-code-show" name="code"><code class="language-php hljs"><ol class="hljs-ln" style="width:100%"><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="1"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line">&lt;a href=<span class="hljs-string">"{{ url('category/delete', ['id' =&gt; <span class="hljs-subst">$v</span>['id']]) }}"</span> <span class="hljs-class"><span class="hljs-keyword">class</span>="<span class="hljs-title">j</span>-<span class="hljs-title">del</span> <span class="hljs-title">text</span>-<span class="hljs-title">danger</span>"&gt;删除&lt;/<span class="hljs-title">a</span>&gt;</span></div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="2"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line"></div></div></li></ol></code><div class="hljs-button {2}" data-title="复制" onclick="hljs.copyCode(event)"></div></pre> 
<p>（2）在<strong>Category</strong>控制器中添加<strong>delete()</strong>方法，具体代码如下：</p> 
<pre data-index="77" class="set-code-show" name="code"><code class="language-php hljs"><ol class="hljs-ln" style="width:100%"><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="1"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line"><span class="hljs-keyword">public</span> <span class="hljs-function"><span class="hljs-keyword">function</span> <span class="hljs-title">delete</span>(<span class="hljs-params"><span class="hljs-variable">$id</span></span>)</span>{</div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="2"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line">        <span class="hljs-keyword">if</span> (!<span class="hljs-variable">$category</span> = <span class="hljs-title class_">Category</span>::<span class="hljs-title function_ invoke__">find</span>(<span class="hljs-variable">$id</span>)) {</div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="3"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line">            <span class="hljs-keyword">return</span> <span class="hljs-title function_ invoke__">response</span>()-&gt;<span class="hljs-title function_ invoke__">json</span>([<span class="hljs-string">'code'</span> =&gt; <span class="hljs-number">0</span>, <span class="hljs-string">'msg'</span> =&gt; <span class="hljs-string">'删除失败，记录不存在。'</span> ]);</div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="4"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line">        }</div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="5"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line">        <span class="hljs-variable">$category</span>-&gt;<span class="hljs-title function_ invoke__">delete</span>();</div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="6"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line">        <span class="hljs-keyword">return</span> <span class="hljs-title function_ invoke__">response</span>()-&gt;<span class="hljs-title function_ invoke__">json</span>([<span class="hljs-string">'code'</span> =&gt; <span class="hljs-number">1</span>, <span class="hljs-string">'msg'</span> =&gt; <span class="hljs-string">'删除成功'</span> ]);</div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="7"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line">    }</div></div></li></ol></code><div class="hljs-button {2}" data-title="复制" onclick="hljs.copyCode(event)"></div></pre> 
<p>（3）在<strong>routes\web.php</strong>文件的栏目路由组中添加删除栏目的路由规则，具体代码如下：</p> 
<pre data-index="78" class="set-code-show" name="code"><code class="language-php hljs">    <span class="hljs-title class_">Route</span>::<span class="hljs-title function_ invoke__">post</span>(<span class="hljs-string">'delete/{id}'</span>, <span class="hljs-string">'CategoryController@delete'</span>);
</code><div class="hljs-button {2}" data-title="复制" onclick="hljs.copyCode(event)"></div></pre> 
<h3 id="%E5%9B%9B.%E5%86%85%E5%AE%B9%E7%AE%A1%E7%90%86"><a name="t20"></a>四.内容管理</h3> 
<h4 id="1.%E5%88%9B%E5%BB%BA%E5%86%85%E5%AE%B9%E8%A1%A8"><a name="t21"></a>1.创建内容表</h4> 
<p>（1）按照上述的步骤创建内容表对应的迁移文件后，在迁移文件的up()方法中添加表结构信息，具体代码如下：</p> 
<pre data-index="79" class="set-code-show" name="code"><code class="language-php hljs"><ol class="hljs-ln" style="width:100%"><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="1"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line"> <span class="hljs-keyword">public</span> <span class="hljs-function"><span class="hljs-keyword">function</span> <span class="hljs-title">up</span>(<span class="hljs-params"></span>)</span></div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="2"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line">    {</div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="3"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line">        <span class="hljs-title class_">Schema</span>::<span class="hljs-title function_ invoke__">create</span>(<span class="hljs-string">'content'</span>, function (Blueprint <span class="hljs-variable">$table</span>) {</div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="4"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line">            <span class="hljs-variable">$table</span>-&gt;<span class="hljs-title function_ invoke__">increments</span>(<span class="hljs-string">'id'</span>)-&gt;<span class="hljs-title function_ invoke__">comment</span>(<span class="hljs-string">'主键'</span>);</div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="5"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line">            <span class="hljs-variable">$table</span>-&gt;<span class="hljs-keyword">integer</span>(<span class="hljs-string">'cid'</span>)-&gt;<span class="hljs-title function_ invoke__">comment</span>(<span class="hljs-string">'栏目id'</span>)-&gt;<span class="hljs-keyword">default</span>(<span class="hljs-number">0</span>);</div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="6"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line">            <span class="hljs-variable">$table</span>-&gt;<span class="hljs-keyword">string</span>(<span class="hljs-string">'title'</span>, <span class="hljs-number">255</span>)-&gt;<span class="hljs-title function_ invoke__">comment</span>(<span class="hljs-string">'标题'</span>);</div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="7"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line">            <span class="hljs-variable">$table</span>-&gt;<span class="hljs-title function_ invoke__">text</span>(<span class="hljs-string">'content'</span>, <span class="hljs-number">255</span>)-&gt;<span class="hljs-title function_ invoke__">comment</span>(<span class="hljs-string">'内容'</span>);</div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="8"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line">            <span class="hljs-variable">$table</span>-&gt;<span class="hljs-title function_ invoke__">char</span>(<span class="hljs-string">'image'</span>, <span class="hljs-number">255</span>)-&gt;<span class="hljs-title function_ invoke__">comment</span>(<span class="hljs-string">'图片'</span>);</div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="9"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line">            <span class="hljs-variable">$table</span>-&gt;<span class="hljs-title function_ invoke__">tinyInteger</span>(<span class="hljs-string">'status'</span>)-&gt;<span class="hljs-title function_ invoke__">comment</span>(<span class="hljs-string">'状态默认1推荐2'</span>)-&gt;<span class="hljs-keyword">default</span>(<span class="hljs-number">1</span>);</div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="10"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line">            <span class="hljs-variable">$table</span>-&gt;<span class="hljs-title function_ invoke__">timestamps</span>();</div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="11"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line">        });</div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="12"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line"> </div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="13"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line">    }</div></div></li></ol></code><div class="hljs-button {2}" data-title="复制" onclick="hljs.copyCode(event)"></div></pre> 
<p>（2）创建内容表对应的模型文件，具体代码如下：</p> 
<pre data-index="80" class="set-code-show" name="code"><code class="language-php hljs">php artisan make:model Content</code><div class="hljs-button {2}" data-title="复制" onclick="hljs.copyCode(event)"></div></pre> 
<p>（3）执行上述命令后，会自动创建<strong>app\Content.php</strong>文件，具体代码如下：</p> 
<pre data-index="81" class="set-code-show" name="code"><code class="language-php hljs"><ol class="hljs-ln" style="width:100%"><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="1"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line"><span class="hljs-meta">&lt;?php</span></div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="2"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line"> </div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="3"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line"><span class="hljs-keyword">namespace</span> <span class="hljs-title class_">App</span>;</div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="4"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line"> </div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="5"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line"><span class="hljs-keyword">use</span> <span class="hljs-title">Illuminate</span>\<span class="hljs-title">Database</span>\<span class="hljs-title">Eloquent</span>\<span class="hljs-title">Model</span>;</div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="6"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line"> </div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="7"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line"><span class="hljs-class"><span class="hljs-keyword">class</span> <span class="hljs-title">Content</span> <span class="hljs-keyword">extends</span> <span class="hljs-title">Model</span></span></div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="8"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line">{</div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="9"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line">    <span class="hljs-keyword">protected</span> <span class="hljs-variable">$table</span> = <span class="hljs-string">"content"</span>;</div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="10"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line">    <span class="hljs-keyword">public</span> <span class="hljs-variable">$fillable</span> = [<span class="hljs-string">'cid'</span>, <span class="hljs-string">'title'</span>, <span class="hljs-string">'content'</span>, <span class="hljs-string">'image'</span>, <span class="hljs-string">'status'</span>];</div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="11"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line">}</div></div></li></ol></code><div class="hljs-button {2}" data-title="复制" onclick="hljs.copyCode(event)"></div></pre> 
<h4 id="2.%E6%B7%BB%E5%8A%A0%E5%86%85%E5%AE%B9"><a name="t22"></a>2.添加内容</h4> 
<p>（1）创建<strong>Content</strong>控制器，具体代码如下：</p> 
<pre data-index="82" class="set-code-show" name="code"><code class="language-php hljs">php artisan make:controller Admin\ContentController</code><div class="hljs-button {2}" data-title="复制" onclick="hljs.copyCode(event)"></div></pre> 
<p>（2）在控制器中引入<strong>add()</strong>方法用于实现添加内容的功能，<strong>save()</strong>方法保存添加的内容，具体代码如下：</p> 
<pre data-index="83" class="set-code-show" name="code"><code class="language-php hljs"><ol class="hljs-ln" style="width:100%"><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="1"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line"> <span class="hljs-keyword">public</span> <span class="hljs-function"><span class="hljs-keyword">function</span> <span class="hljs-title">add</span>(<span class="hljs-params"></span>)</span></div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="2"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line">    {</div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="3"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line">        <span class="hljs-variable">$data</span> = <span class="hljs-title class_">Category</span>::<span class="hljs-title function_ invoke__">orderBy</span>(<span class="hljs-string">'sort'</span>, <span class="hljs-string">'asc'</span>)-&gt;<span class="hljs-title function_ invoke__">get</span>()-&gt;<span class="hljs-title function_ invoke__">toArray</span>();</div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="4"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line">        <span class="hljs-variable">$cate</span> = <span class="hljs-keyword">new</span> <span class="hljs-title class_">CategoryController</span>();</div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="5"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line">        <span class="hljs-variable">$category</span> = <span class="hljs-variable">$cate</span>-&gt;<span class="hljs-title function_ invoke__">getTreeListCheckLeaf</span>(<span class="hljs-variable">$data</span>);</div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="6"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line">        <span class="hljs-keyword">return</span> <span class="hljs-title function_ invoke__">view</span>(<span class="hljs-string">'admin.content.add'</span>, [<span class="hljs-string">'category'</span> =&gt; <span class="hljs-variable">$category</span>]);</div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="7"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line">    }</div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="8"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line"> </div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="9"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line">    <span class="hljs-keyword">public</span> <span class="hljs-function"><span class="hljs-keyword">function</span> <span class="hljs-title">save</span>(<span class="hljs-params">Request <span class="hljs-variable">$request</span></span>)</span></div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="10"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line">    {</div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="11"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line">        <span class="hljs-variable">$data</span> = <span class="hljs-variable">$request</span>-&gt;<span class="hljs-title function_ invoke__">all</span>();</div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="12"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line">        <span class="hljs-variable language_">$this</span>-&gt;<span class="hljs-title function_ invoke__">validate</span>(<span class="hljs-variable">$request</span>,[</div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="13"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line">            <span class="hljs-string">'cid'</span>=&gt;<span class="hljs-string">'required'</span>,</div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="14"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line">            <span class="hljs-string">'title'</span>=&gt;<span class="hljs-string">'required'</span></div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="15"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line">        ],[</div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="16"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line">            <span class="hljs-string">'cid.require'</span>=&gt;<span class="hljs-string">'分类不能为空'</span>,</div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="17"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line">            <span class="hljs-string">'title.require'</span>=&gt;<span class="hljs-string">'标题不能为空'</span></div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="18"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line">        ]);</div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="19"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line">        <span class="hljs-keyword">if</span>(<span class="hljs-keyword">isset</span>(<span class="hljs-variable">$data</span>[<span class="hljs-string">'id'</span>])){</div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="20"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line">            <span class="hljs-variable">$id</span> = <span class="hljs-variable">$data</span>[<span class="hljs-string">'id'</span>];</div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="21"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line">            <span class="hljs-keyword">unset</span>(<span class="hljs-variable">$data</span>[<span class="hljs-string">'id'</span>]);</div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="22"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line">            <span class="hljs-keyword">unset</span>(<span class="hljs-variable">$data</span>[<span class="hljs-string">'_token'</span>]);</div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="23"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line">            <span class="hljs-variable">$res</span> = <span class="hljs-title class_">Content</span>::<span class="hljs-title function_ invoke__">where</span>(<span class="hljs-string">'id'</span>,<span class="hljs-variable">$id</span>)-&gt;<span class="hljs-title function_ invoke__">update</span>(<span class="hljs-variable">$data</span>);</div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="24"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line">            <span class="hljs-variable">$type</span> = <span class="hljs-variable">$res</span> ? <span class="hljs-string">"message"</span> : <span class="hljs-string">"tip"</span>;</div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="25"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line">            <span class="hljs-variable">$message</span> = <span class="hljs-variable">$res</span> ? <span class="hljs-string">"修改成功"</span> : <span class="hljs-string">"修改失败"</span>;</div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="26"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line">            <span class="hljs-keyword">return</span> <span class="hljs-title function_ invoke__">redirect</span>(<span class="hljs-string">'content'</span>)-&gt;<span class="hljs-title function_ invoke__">with</span>(<span class="hljs-variable">$type</span>, <span class="hljs-variable">$message</span>);</div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="27"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line">        }</div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="28"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line"> </div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="29"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line">        <span class="hljs-variable">$re</span> = <span class="hljs-title class_">Content</span>::<span class="hljs-title function_ invoke__">create</span>(<span class="hljs-variable">$data</span>);</div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="30"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line">        <span class="hljs-keyword">if</span>(<span class="hljs-variable">$re</span>){</div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="31"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line">            <span class="hljs-keyword">return</span> <span class="hljs-title function_ invoke__">redirect</span>(<span class="hljs-string">'content'</span>)-&gt;<span class="hljs-title function_ invoke__">with</span>(<span class="hljs-string">'message'</span>,<span class="hljs-string">'添加成功'</span>);</div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="32"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line">        }<span class="hljs-keyword">else</span>{</div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="33"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line">            <span class="hljs-keyword">return</span> <span class="hljs-title function_ invoke__">redirect</span>(<span class="hljs-string">'content/add'</span>)-&gt;<span class="hljs-title function_ invoke__">with</span>(<span class="hljs-string">'tip'</span>,<span class="hljs-string">'添加失败'</span>);</div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="34"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line">        }</div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="35"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line">    }</div></div></li></ol></code><div class="hljs-button {2}" data-title="复制" onclick="hljs.copyCode(event)"></div></pre> 
<p>（3）在控制器中导入<strong>Category模型的命名空间</strong>和<strong>Content的命名空间</strong>，具体代码如下：</p> 
<pre data-index="84" class="set-code-show" name="code"><code class="language-php hljs"><ol class="hljs-ln" style="width:100%"><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="1"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line"><span class="hljs-keyword">use</span> <span class="hljs-title">App</span>\<span class="hljs-title">Category</span>;</div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="2"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line"><span class="hljs-keyword">use</span> <span class="hljs-title">App</span>\<span class="hljs-title">Content</span>;</div></div></li></ol></code><div class="hljs-button {2}" data-title="复制" onclick="hljs.copyCode(event)"></div></pre> 
<p>（4）创建<strong>resources\views\admin\content\add.blade.php</strong>视图文件，具体代码如下：</p> 
<pre data-index="85" class="set-code-show" name="code"><code class="language-php hljs"><ol class="hljs-ln hundred" style="width:1673px"><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="1"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line">@<span class="hljs-keyword">extends</span>(<span class="hljs-string">'admin/layouts/admin'</span>)</div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="2"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line">@<span class="hljs-title function_ invoke__">section</span>(<span class="hljs-string">'title'</span>, <span class="hljs-string">'添加内容'</span>)</div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="3"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line">@<span class="hljs-title function_ invoke__">section</span>(<span class="hljs-string">'main'</span>)</div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="4"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line">&lt;div <span class="hljs-class"><span class="hljs-class"><span class="hljs-keyword">class</span>="<span class="hljs-title">main</span>-<span class="hljs-title">title</span>"&gt;&lt;<span class="hljs-title">h2</span>&gt;添加内容&lt;/<span class="hljs-title">h2</span>&gt;&lt;/<span class="hljs-title">div</span>&gt;</span></span></div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="5"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line"><span class="hljs-class">&lt;<span class="hljs-title">div</span> <span class="hljs-title">class</span>="<span class="hljs-title">main</span>-<span class="hljs-title">section</span>"&gt;</span></div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="6"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line"><span class="hljs-class">  &lt;<span class="hljs-title">div</span> <span class="hljs-title">style</span>="<span class="hljs-title">width</span>:80%"&gt;</span></div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="7"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line"><span class="hljs-class">    &lt;!-- 添加内容表单 --&gt;</span></div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="8"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line"><span class="hljs-class">    &lt;<span class="hljs-title">form</span> <span class="hljs-title">method</span>="<span class="hljs-title">post</span>" <span class="hljs-title">action</span>="</span>{{ <span class="hljs-title function_ invoke__">url</span>(<span class="hljs-string">'/content/save'</span>) }}<span class="hljs-string">" class="</span>j-form<span class="hljs-string"><span class="hljs-string">"&gt;</span></span></div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="9"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line"><span class="hljs-string">      &lt;div class="</span>form-group row<span class="hljs-string"><span class="hljs-string">"&gt;</span></span></div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="10"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line"><span class="hljs-string">        &lt;label class="</span>col-sm-<span class="hljs-number">2</span> col-form-label<span class="hljs-string"><span class="hljs-string">"&gt;所属分类&lt;/label&gt;</span></span></div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="11"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line"><span class="hljs-string">        &lt;div class="</span>col-sm-<span class="hljs-number">10</span><span class="hljs-string"><span class="hljs-string">"&gt;</span></span></div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="12"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line"><span class="hljs-string">          &lt;select name="</span>cid<span class="hljs-string">" class="</span>form-control<span class="hljs-string">" style="</span>width:<span class="hljs-number">200</span>px;<span class="hljs-string"><span class="hljs-string">"&gt;</span></span></div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="13"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line"><span class="hljs-string">            &lt;!-- 分类下拉列表 --&gt;</span></div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="14"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line"><span class="hljs-string">            @foreach(<span class="hljs-subst">$category</span> as <span class="hljs-subst">$v</span>)</span></div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="15"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line"><span class="hljs-string">              @if(<span class="hljs-subst">$v</span>['level'])</span></div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="16"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line"><span class="hljs-string">                &lt;option value="</span>{{<span class="hljs-variable">$v</span>[<span class="hljs-string">'id'</span>]}}<span class="hljs-string"><span class="hljs-string">"&gt;</span></span></div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="17"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line"><span class="hljs-string">                  &lt;small class="</span>text-muted<span class="hljs-string"><span class="hljs-string">"&gt;├──&lt;/small&gt;{<span class="hljs-subst">{$v['name']}</span>}</span></span></div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="18"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line"><span class="hljs-string">                &lt;/option&gt;</span></div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="19"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line"><span class="hljs-string">              @else</span></div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="20"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line"><span class="hljs-string">                &lt;option value="</span>{{<span class="hljs-variable">$v</span>[<span class="hljs-string">'id'</span>]}}<span class="hljs-string"><span class="hljs-string">"&gt; {<span class="hljs-subst">{$v['name']}</span>}&lt;/option&gt;</span></span></div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="21"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line"><span class="hljs-string">              @endif</span></div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="22"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line"><span class="hljs-string">            @endforeach</span></div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="23"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line"><span class="hljs-string">          &lt;/select&gt;</span></div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="24"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line"><span class="hljs-string">        &lt;/div&gt;</span></div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="25"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line"><span class="hljs-string">      &lt;/div&gt;</span></div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="26"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line"><span class="hljs-string">      &lt;div class="</span>form-group row<span class="hljs-string"><span class="hljs-string">"&gt;</span></span></div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="27"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line"><span class="hljs-string">        &lt;label class="</span>col-sm-<span class="hljs-number">2</span> col-form-label<span class="hljs-string"><span class="hljs-string">"&gt;标题&lt;/label&gt;</span></span></div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="28"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line"><span class="hljs-string">        &lt;div class="</span>col-sm-<span class="hljs-number">10</span><span class="hljs-string"><span class="hljs-string">"&gt;</span></span></div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="29"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line"><span class="hljs-string">          &lt;input type="</span>text<span class="hljs-string">" name="</span>title<span class="hljs-string">" class="</span>form-control<span class="hljs-string">" style="</span>width:<span class="hljs-number">200</span>px;<span class="hljs-string"><span class="hljs-string">"&gt;</span></span></div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="30"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line"><span class="hljs-string">        &lt;/div&gt;</span></div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="31"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line"><span class="hljs-string">      &lt;/div&gt;</span></div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="32"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line"><span class="hljs-string">      &lt;!-- 上传图片按钮 --&gt;</span></div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="33"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line"><span class="hljs-string">      &lt;div class="</span>form-group row<span class="hljs-string"><span class="hljs-string">"&gt;</span></span></div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="34"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line"><span class="hljs-string">        &lt;label class="</span>col-sm-<span class="hljs-number">2</span> col-form-label<span class="hljs-string"><span class="hljs-string">"&gt;图片&lt;/label&gt;</span></span></div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="35"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line"><span class="hljs-string">        &lt;div class="</span>col-sm-<span class="hljs-number">10</span><span class="hljs-string"><span class="hljs-string">"&gt;</span></span></div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="36"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line"><span class="hljs-string">          &lt;input type="</span>file<span class="hljs-string">" id="</span>file1<span class="hljs-string">" name="</span>image<span class="hljs-string">" value="</span>上传图片<span class="hljs-string">" multiple="</span><span class="hljs-literal">true</span><span class="hljs-string"><span class="hljs-string">"&gt;</span></span></div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="37"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line"><span class="hljs-string">        &lt;/div&gt;</span></div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="38"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line"><span class="hljs-string">        &lt;div class="</span>col-sm-<span class="hljs-number">10</span> offset-sm-<span class="hljs-number">2</span><span class="hljs-string"><span class="hljs-string">"&gt;</span></span></div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="39"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line"><span class="hljs-string">          &lt;div class="</span>upload-img-box<span class="hljs-string">" id="</span>uploadImg<span class="hljs-string"><span class="hljs-string">"&gt;&lt;/div&gt;</span></span></div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="40"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line"><span class="hljs-string">        &lt;/div&gt;</span></div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="41"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line"><span class="hljs-string">      &lt;/div&gt;</span></div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="42"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line"><span class="hljs-string">      &lt;div class="</span>form-group row<span class="hljs-string"><span class="hljs-string">"&gt;</span></span></div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="43"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line"><span class="hljs-string">        &lt;label class="</span>col-sm-<span class="hljs-number">2</span> col-form-label<span class="hljs-string"><span class="hljs-string">"&gt;简介&lt;/label&gt;</span></span></div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="44"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line"><span class="hljs-string">        &lt;div class="</span>col-sm-<span class="hljs-number">10</span><span class="hljs-string"><span class="hljs-string">"&gt;</span></span></div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="45"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line"><span class="hljs-string">          &lt;!-- &lt;textarea class="</span>j-goods-content<span class="hljs-string">" name="</span>content<span class="hljs-string">" style="</span>height:<span class="hljs-number">500</span>px<span class="hljs-string"><span class="hljs-string">"&gt;&lt;/textarea&gt; --&gt;</span></span></div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="46"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line"><span class="hljs-string">          &lt;script type="</span>text/plain<span class="hljs-string">" class="</span>j-goods-content<span class="hljs-string">" name="</span>content<span class="hljs-string">" style="</span>height:<span class="hljs-number">500</span>px<span class="hljs-string"><span class="hljs-string">"&gt;&lt;/script&gt;</span></span></div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="47"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line"><span class="hljs-string">        &lt;/div&gt;</span></div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="48"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line"><span class="hljs-string">      &lt;/div&gt;</span></div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="49"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line"><span class="hljs-string">      &lt;div class="</span>form-group row<span class="hljs-string"><span class="hljs-string">"&gt;</span></span></div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="50"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line"><span class="hljs-string">        &lt;label class="</span>col-sm-<span class="hljs-number">2</span> col-form-label<span class="hljs-string"><span class="hljs-string">"&gt;状态&lt;/label&gt;</span></span></div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="51"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line"><span class="hljs-string">        &lt;div class="</span>col-sm-<span class="hljs-number">10</span><span class="hljs-string"><span class="hljs-string">"&gt;</span></span></div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="52"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line"><span class="hljs-string">          &lt;div class="</span>form-check form-check-inline<span class="hljs-string">" style="</span>height:<span class="hljs-number">38</span>px<span class="hljs-string"><span class="hljs-string">"&gt;</span></span></div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="53"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line"><span class="hljs-string">            &lt;input class="</span>form-check-input<span class="hljs-string">" id="</span>inlineRadio1<span class="hljs-string">" type="</span>radio<span class="hljs-string">" name="</span>status<span class="hljs-string">" value="</span><span class="hljs-number">1</span><span class="hljs-string"><span class="hljs-string">" checked&gt;</span></span></div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="54"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line"><span class="hljs-string">            &lt;label class="</span>form-check-label<span class="hljs-string">" for="</span>inlineRadio1<span class="hljs-string"><span class="hljs-string">"&gt;默认&lt;/label&gt;</span></span></div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="55"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line"><span class="hljs-string">          &lt;/div&gt;</span></div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="56"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line"><span class="hljs-string">          &lt;div class="</span>form-check form-check-inline<span class="hljs-string">" style="</span>height:<span class="hljs-number">38</span>px<span class="hljs-string"><span class="hljs-string">"&gt;</span></span></div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="57"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line"><span class="hljs-string">            &lt;input class="</span>form-check-input<span class="hljs-string">" id="</span>inlineRadio2<span class="hljs-string">" type="</span>radio<span class="hljs-string">" name="</span>status<span class="hljs-string">" value="</span><span class="hljs-number">2</span><span class="hljs-string"><span class="hljs-string">"&gt;</span></span></div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="58"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line"><span class="hljs-string">            &lt;label class="</span>form-check-label<span class="hljs-string">" for="</span>inlineRadio2<span class="hljs-string"><span class="hljs-string">"&gt;推荐&lt;/label&gt;</span></span></div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="59"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line"><span class="hljs-string">          &lt;/div&gt;</span></div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="60"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line"><span class="hljs-string">        &lt;/div&gt;</span></div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="61"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line"><span class="hljs-string">      &lt;/div&gt;</span></div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="62"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line"><span class="hljs-string">      &lt;div class="</span>form-group row<span class="hljs-string"><span class="hljs-string">"&gt;</span></span></div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="63"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line"><span class="hljs-string">        &lt;div class="</span>col-sm-<span class="hljs-number">10</span><span class="hljs-string"><span class="hljs-string">"&gt;</span></span></div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="64"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line"><span class="hljs-string">          {{csrf_field()}}</span></div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="65"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line"><span class="hljs-string">          &lt;button type="</span>submit<span class="hljs-string">" class="</span>btn btn-primary mr-<span class="hljs-number">2</span><span class="hljs-string"><span class="hljs-string">"&gt;提交表单&lt;/button&gt;</span></span></div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="66"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line"><span class="hljs-string">          &lt;a href="</span>{{<span class="hljs-title function_ invoke__">url</span>(<span class="hljs-string">'content'</span>)}}<span class="hljs-string">" class="</span>btn btn-secondary<span class="hljs-string"><span class="hljs-string">"&gt;返回列表&lt;/a&gt;</span></span></div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="67"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line"><span class="hljs-string">        &lt;/div&gt;</span></div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="68"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line"><span class="hljs-string">      &lt;/div&gt;</span></div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="69"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line"><span class="hljs-string">    &lt;/form&gt;</span></div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="70"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line"><span class="hljs-string">  &lt;/div&gt;</span></div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="71"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line"><span class="hljs-string">&lt;/div&gt;</span></div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="72"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line"><span class="hljs-string">&lt;link href="</span>{{<span class="hljs-title function_ invoke__">asset</span>(<span class="hljs-string">'admin'</span>)}}/common/uploader/uploadifive.css<span class="hljs-string">" rel="</span>stylesheet<span class="hljs-string"><span class="hljs-string">" /&gt;</span></span></div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="73"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line"><span class="hljs-string">&lt;script src="</span>{{<span class="hljs-title function_ invoke__">asset</span>(<span class="hljs-string">'admin'</span>)}}/common/uploader/jquery.uploadifive.js<span class="hljs-string"><span class="hljs-string">"&gt;&lt;/script&gt;</span></span></div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="74"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line"><span class="hljs-string">&lt;script src="</span>{{<span class="hljs-title function_ invoke__">asset</span>(<span class="hljs-string">'admin'</span>)}}/common/editor/ueditor1.<span class="hljs-number">4.3</span>.<span class="hljs-number">3</span>/ueditor.config.js<span class="hljs-string"><span class="hljs-string">"&gt;&lt;/script&gt;</span></span></div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="75"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line"><span class="hljs-string">&lt;script src="</span>{{<span class="hljs-title function_ invoke__">asset</span>(<span class="hljs-string">'admin'</span>)}}/common/editor/ueditor1.<span class="hljs-number">4.3</span>.<span class="hljs-number">3</span>/ueditor.all.min.js<span class="hljs-string"><span class="hljs-string">"&gt;&lt;/script&gt;</span></span></div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="76"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line"><span class="hljs-string">&lt;script src="</span>{{<span class="hljs-title function_ invoke__">asset</span>(<span class="hljs-string">'admin'</span>)}}/common/editor/main.editor.js<span class="hljs-string"><span class="hljs-string">"&gt;&lt;/script&gt;</span></span></div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="77"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line"><span class="hljs-string">&lt;script&gt;</span></div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="78"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line"><span class="hljs-string">    main.menuActive('addcontent');</span></div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="79"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line"><span class="hljs-string">    $(function() {</span></div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="80"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line"><span class="hljs-string">      $('#file1').uploadifive({</span></div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="81"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line"><span class="hljs-string">        'auto'            : true,</span></div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="82"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line"><span class="hljs-string">        'fileObjName'     : 'image',</span></div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="83"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line"><span class="hljs-string">        'fileType'        : 'image',</span></div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="84"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line"><span class="hljs-string">        'buttonText'      : '上传图片',</span></div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="85"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line"><span class="hljs-string">        'formData'        : { '_token' : "</span>{{ <span class="hljs-title function_ invoke__">csrf_token</span>() }}<span class="hljs-string"><span class="hljs-string">" },</span></span></div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="86"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line"><span class="hljs-string">        'method'          : 'post',</span></div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="87"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line"><span class="hljs-string">        'queueID'         : 'uploadImg',</span></div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="88"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line"><span class="hljs-string">        'removeCompleted' : true,</span></div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="89"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line"><span class="hljs-string">        'uploadScript'    : '{{ url('content/upload')}}',</span></div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="90"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line"><span class="hljs-string">        'onUploadComplete': uploadPicture_icon</span></div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="91"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line"><span class="hljs-string">      });</span></div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="92"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line"><span class="hljs-string">    });</span></div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="93"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line"><span class="hljs-string">    function uploadPicture_icon(file, data) {</span></div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="94"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line"><span class="hljs-string">      var obj = $.parseJSON(data);</span></div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="95"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line"><span class="hljs-string">      var src = '';</span></div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="96"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line"><span class="hljs-string">      if (obj.code) {</span></div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="97"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line"><span class="hljs-string">        filename = obj.data.filename;</span></div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="98"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line"><span class="hljs-string">        path = obj.data.path;</span></div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="99"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line"><span class="hljs-string">        $('.upload-img-box').empty();</span></div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="100"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line"><span class="hljs-string">        $('.upload-img-box').html(</span></div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="101"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line"><span class="hljs-string">          '&lt;div class="</span>upload-pre-item<span class="hljs-string">" style="</span>max-height:<span class="hljs-number">100</span>%;<span class="hljs-string">"&gt;&lt;img src="</span><span class="hljs-string">' + path + '</span><span class="hljs-string">" style="</span>width:<span class="hljs-number">100</span>px;height:<span class="hljs-number">100</span>px<span class="hljs-string">"/&gt; &lt;input type="</span>hidden<span class="hljs-string">" name="</span>image<span class="hljs-string">" value="</span><span class="hljs-string">'+filename+'</span><span class="hljs-string">" class="</span>icon_banner<span class="hljs-string"><span class="hljs-string">"/&gt;&lt;/div&gt;'</span></span></div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="102"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line"><span class="hljs-string">        );</span></div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="103"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line"><span class="hljs-string">      } else {</span></div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="104"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line"><span class="hljs-string">        alert(data.info);</span></div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="105"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line"><span class="hljs-string">      }</span></div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="106"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line"><span class="hljs-string">    }</span></div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="107"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line"><span class="hljs-string">    main.editor($('.j-goods-content'), 'goods_edit', function(opt) {</span></div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="108"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line"><span class="hljs-string">      opt.UEDITOR_HOME_URL = '{{asset('admin')}}/common/editor/ueditor1.4.3.3/';</span></div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="109"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line"><span class="hljs-string">    }, function(editor) {</span></div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="110"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line"><span class="hljs-string">      $('.j-form').submit(function() {</span></div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="111"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line"><span class="hljs-string">        editor.sync();</span></div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="112"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line"><span class="hljs-string">      });</span></div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="113"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line"><span class="hljs-string">    });</span></div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="114"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line"><span class="hljs-string">&lt;/script&gt;</span></div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="115"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line"><span class="hljs-string">@endsection</span></div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="116"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line"><span class="hljs-string"></span></div></div></li></ol></code><div class="hljs-button {2}" data-title="复制" onclick="hljs.copyCode(event)"></div></pre> 
<p>（5）在<strong>routes\web.php</strong>文件在添加内容管理的路由组，具体代码如下：</p> 
<pre data-index="86" class="set-code-show" name="code"><code class="language-php hljs"><ol class="hljs-ln" style="width:100%"><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="1"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line"><span class="hljs-title class_">Route</span>::<span class="hljs-title function_ invoke__">prefix</span>(<span class="hljs-string">'content'</span>)-&gt;<span class="hljs-title function_ invoke__">namespace</span>(<span class="hljs-string">'Admin'</span>)-&gt;<span class="hljs-title function_ invoke__">middleware</span>([<span class="hljs-string">'Admin'</span>])-&gt;<span class="hljs-title function_ invoke__">group</span>(function () {</div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="2"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line"> </div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="3"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line">    <span class="hljs-title class_">Route</span>::<span class="hljs-title function_ invoke__">get</span>(<span class="hljs-string">'add'</span>, <span class="hljs-string">'ContentController@add'</span>);</div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="4"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line">    <span class="hljs-title class_">Route</span>::<span class="hljs-title function_ invoke__">post</span>(<span class="hljs-string">'save'</span>, <span class="hljs-string">'ContentController@save'</span>);</div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="5"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line">});</div></div></li></ol></code><div class="hljs-button {2}" data-title="复制" onclick="hljs.copyCode(event)"></div></pre> 
<p>（6）修改<strong>admin.blade.php</strong>,为添加内容的菜单项添加链接，具体代码如下：</p> 
<pre data-index="87" class="set-code-show" name="code"><code class="language-php hljs"><ol class="hljs-ln" style="width:100%"><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="1"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line">&lt;a href=<span class="hljs-string">"{{ url('content/add') }}"</span> data-name=<span class="hljs-string">"addcontent"</span>&gt;</div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="2"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line">              &lt;i <span class="hljs-class"><span class="hljs-keyword">class</span>="<span class="hljs-title">fa</span> <span class="hljs-title">fa</span>-<span class="hljs-title">list</span> <span class="hljs-title">fa</span>-<span class="hljs-title">fw</span>"&gt;&lt;/<span class="hljs-title">i</span>&gt;添加&lt;/<span class="hljs-title">a</span>&gt;</span></div></div></li></ol></code><div class="hljs-button {2}" data-title="复制" onclick="hljs.copyCode(event)"></div></pre> 
<h4 id="3.%E4%B8%8A%E4%BC%A0%E5%9B%BE%E7%89%87"><a name="t23"></a>3.上传图片</h4> 
<p>（1）在添加内容的视图中添加上传图片的按钮，具体代码如下：</p> 
<pre data-index="88" class="set-code-show" name="code"><code class="language-php hljs"><ol class="hljs-ln" style="width:100%"><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="1"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line">&lt;div <span class="hljs-class"><span class="hljs-class"><span class="hljs-keyword">class</span>="<span class="hljs-title">form</span>-<span class="hljs-title">group</span> <span class="hljs-title">row</span>"&gt;</span></span></div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="2"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line"><span class="hljs-class">        &lt;<span class="hljs-title">label</span> <span class="hljs-title">class</span>="<span class="hljs-title">col</span>-<span class="hljs-title">sm</span>-2 <span class="hljs-title">col</span>-<span class="hljs-title">form</span>-<span class="hljs-title">label</span>"&gt;图片&lt;/<span class="hljs-title">label</span>&gt;</span></div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="3"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line"><span class="hljs-class">        &lt;<span class="hljs-title">div</span> <span class="hljs-title">class</span>="<span class="hljs-title">col</span>-<span class="hljs-title">sm</span>-10"&gt;</span></div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="4"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line"><span class="hljs-class">          &lt;<span class="hljs-title">input</span> <span class="hljs-title">type</span>="<span class="hljs-title">file</span>" <span class="hljs-title">id</span>="<span class="hljs-title">file1</span>" <span class="hljs-title">name</span>="<span class="hljs-title">image</span>" <span class="hljs-title">value</span>="上传图片" <span class="hljs-title">multiple</span>="<span class="hljs-title">true</span>"&gt;</span></div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="5"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line"><span class="hljs-class">        &lt;/<span class="hljs-title">div</span>&gt;</span></div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="6"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line"><span class="hljs-class">        &lt;<span class="hljs-title">div</span> <span class="hljs-title">class</span>="<span class="hljs-title">col</span>-<span class="hljs-title">sm</span>-10 <span class="hljs-title">offset</span>-<span class="hljs-title">sm</span>-2"&gt;</span></div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="7"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line"><span class="hljs-class">          &lt;<span class="hljs-title">div</span> <span class="hljs-title">class</span>="<span class="hljs-title">upload</span>-<span class="hljs-title">img</span>-<span class="hljs-title">box</span>" <span class="hljs-title">id</span>="<span class="hljs-title">uploadImg</span>"&gt;&lt;/<span class="hljs-title">div</span>&gt;</span></div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="8"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line"><span class="hljs-class">        &lt;/<span class="hljs-title">div</span>&gt;</span></div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="9"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line"><span class="hljs-class">      &lt;/<span class="hljs-title">div</span>&gt;</span></div></div></li></ol></code><div class="hljs-button {2}" data-title="复制" onclick="hljs.copyCode(event)"></div></pre> 
<p>（2）在视图中引入上传文件所需的样式和JavaScript代码，具体代码如下：</p> 
<pre data-index="89" class="set-code-show" name="code"><code class="language-php hljs"><ol class="hljs-ln" style="width:100%"><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="1"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line">&lt;link href=<span class="hljs-string">"{{asset('admin')}}/common/uploader/uploadifive.css"</span> rel=<span class="hljs-string">"stylesheet"</span> /&gt;</div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="2"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line">&lt;script src=<span class="hljs-string">"{{asset('admin')}}/common/uploader/jquery.uploadifive.js"</span>&gt;&lt;/script&gt;</div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="3"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line">&lt;script src=<span class="hljs-string">"{{asset('admin')}}/common/uploader/jquery.uploadifive.min.js"</span>&gt;&lt;/script&gt;</div></div></li></ol></code><div class="hljs-button {2}" data-title="复制" onclick="hljs.copyCode(event)"></div></pre> 
<p>（3）在<strong>Content</strong>控制器中编写upload()方法，具体代码如下：</p> 
<pre data-index="90" class="set-code-show" name="code"><code class="language-php hljs"><ol class="hljs-ln" style="width:100%"><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="1"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line"> <span class="hljs-keyword">public</span> <span class="hljs-function"><span class="hljs-keyword">function</span> <span class="hljs-title">upload</span>(<span class="hljs-params">Request <span class="hljs-variable">$request</span></span>)</span></div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="2"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line">    {</div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="3"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line">        <span class="hljs-keyword">if</span> (<span class="hljs-variable">$request</span>-&gt;<span class="hljs-title function_ invoke__">hasFile</span>(<span class="hljs-string">'image'</span>)) {</div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="4"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line">            <span class="hljs-variable">$image</span> = <span class="hljs-variable">$request</span>-&gt;<span class="hljs-title function_ invoke__">file</span>(<span class="hljs-string">'image'</span>);</div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="5"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line">            <span class="hljs-keyword">if</span> (<span class="hljs-variable">$image</span>-&gt;<span class="hljs-title function_ invoke__">isValid</span>()) {</div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="6"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line">                <span class="hljs-variable">$name</span> = <span class="hljs-title function_ invoke__">md5</span>(<span class="hljs-title function_ invoke__">microtime</span>(<span class="hljs-literal">true</span>)) . <span class="hljs-string">'.'</span> . <span class="hljs-variable">$image</span>-&gt;<span class="hljs-title function_ invoke__">extension</span>();</div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="7"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line">                <span class="hljs-variable">$image</span>-&gt;<span class="hljs-title function_ invoke__">move</span>(<span class="hljs-string">'static/upload'</span>, <span class="hljs-variable">$name</span>);</div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="8"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line">                <span class="hljs-variable">$path</span> = <span class="hljs-string">'/static/upload/'</span> . <span class="hljs-variable">$name</span>;</div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="9"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line">                <span class="hljs-variable">$returndata</span>  = <span class="hljs-keyword">array</span>(</div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="10"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line">                    <span class="hljs-string">'filename'</span> =&gt; <span class="hljs-variable">$name</span>,</div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="11"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line">                    <span class="hljs-string">'path'</span> =&gt; <span class="hljs-variable">$path</span></div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="12"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line">                );</div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="13"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line">                <span class="hljs-variable">$result</span> = [</div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="14"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line">                    <span class="hljs-string">'code'</span> =&gt; <span class="hljs-number">1</span>,</div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="15"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line">                    <span class="hljs-string">'msg'</span>  =&gt; <span class="hljs-string">'上传成功'</span>,</div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="16"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line">                    <span class="hljs-string">'time'</span> =&gt; <span class="hljs-title function_ invoke__">time</span>(),</div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="17"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line">                    <span class="hljs-string">'data'</span> =&gt; <span class="hljs-variable">$returndata</span>,</div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="18"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line">                ];</div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="19"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line">                <span class="hljs-keyword">return</span> <span class="hljs-title function_ invoke__">response</span>()-&gt;<span class="hljs-title function_ invoke__">json</span>(<span class="hljs-variable">$result</span>);</div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="20"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line">            }</div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="21"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line">            <span class="hljs-keyword">return</span> <span class="hljs-variable">$image</span>-&gt;<span class="hljs-title function_ invoke__">getErrorMessage</span>();</div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="22"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line">        }</div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="23"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line">        <span class="hljs-keyword">return</span> <span class="hljs-string">'文件上传失败'</span>;</div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="24"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line">    }</div></div></li></ol></code><div class="hljs-button {2}" data-title="复制" onclick="hljs.copyCode(event)"></div></pre> 
<p>（4）在<strong>routes\web.php</strong>文件中内容的路由组中添加上传图片的路由规则，具体代码如下：</p> 
<pre data-index="91" class="set-code-show" name="code"><code class="language-php hljs">    <span class="hljs-title class_">Route</span>::<span class="hljs-title function_ invoke__">post</span>(<span class="hljs-string">'upload'</span>, <span class="hljs-string">'ContentController@upload'</span>);
</code><div class="hljs-button {2}" data-title="复制" onclick="hljs.copyCode(event)"></div></pre> 
<h4 id="4.%E6%95%B4%E5%90%88UFditor"><a name="t24"></a>4.整合UFditor</h4> 
<p>（1）创建<strong>public\admin\common\editor\main.editor.js</strong>文件，具体代码如下：</p> 
<pre data-index="92" class="set-code-show" name="code"><code class="language-php hljs"><ol class="hljs-ln" style="width:100%"><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="1"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line">(<span class="hljs-function"><span class="hljs-keyword">function</span>(<span class="hljs-params">$, main</span>) </span>{</div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="2"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line">  <span class="hljs-keyword">var</span> def = {</div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="3"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line">    UEDITOR_HOME_URL: <span class="hljs-string">''</span>,       <span class="hljs-comment">// UEditor URL</span></div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="4"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line">    serverUrl: <span class="hljs-string">''</span>,				<span class="hljs-comment">// UEditor内置上传地址设为空</span></div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="5"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line">    autoHeightEnabled: <span class="hljs-literal">false</span>,	<span class="hljs-comment">// 关闭自动调整高度</span></div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="6"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line">    wordCount: <span class="hljs-literal">false</span>,			<span class="hljs-comment">// 关闭字数统计</span></div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="7"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line">    toolbars: [[<span class="hljs-string">'fullscreen'</span>, <span class="hljs-string">'source'</span>, <span class="hljs-string">'|'</span>,  <span class="hljs-comment">// 自定义工具栏按钮</span></div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="8"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line">     <span class="hljs-string">'undo'</span>, <span class="hljs-string">'redo'</span>, <span class="hljs-string">'|'</span>,  <span class="hljs-string">'bold'</span>, <span class="hljs-string">'italic'</span>, <span class="hljs-string">'underline'</span>, <span class="hljs-string">'strikethrough'</span>, </div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="9"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line">     <span class="hljs-string">'forecolor'</span>, <span class="hljs-string">'backcolor'</span>, <span class="hljs-string">'fontfamily'</span>, <span class="hljs-string">'fontsize'</span>, <span class="hljs-string">'paragraph'</span>, <span class="hljs-string">'link'</span>,</div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="10"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line">     <span class="hljs-string">'blockquote'</span>, <span class="hljs-string">'insertorderedlist'</span>, <span class="hljs-string">'insertunorderedlist'</span>, <span class="hljs-string">'|'</span>,</div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="11"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line">     <span class="hljs-string">'inserttable'</span>, <span class="hljs-string">'insertrow'</span>, <span class="hljs-string">'insertcol'</span>, <span class="hljs-string">'|'</span>, <span class="hljs-string">'drafts'</span>]]</div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="12"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line">  };</div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="13"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line">  <span class="hljs-keyword">var</span> instances = {};</div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="14"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line">  main.editor = <span class="hljs-function"><span class="hljs-keyword">function</span>(<span class="hljs-params">obj, id, before, ready</span>) </span>{</div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="15"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line">    <span class="hljs-keyword">var</span> opt = $.<span class="hljs-title function_ invoke__">extend</span>(<span class="hljs-literal">true</span>, {}, def);</div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="16"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line">    <span class="hljs-title function_ invoke__">before</span>(opt);</div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="17"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line">    <span class="hljs-keyword">if</span> (instances[id]) {</div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="18"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line">      instances[id].<span class="hljs-title function_ invoke__">destroy</span>();</div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="19"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line">      $(<span class="hljs-string">'#'</span> + id).<span class="hljs-title function_ invoke__">removeAttr</span>(<span class="hljs-string">'id'</span>);</div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="20"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line">    }</div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="21"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line">    <span class="hljs-keyword">return</span> instances[id] = <span class="hljs-title function_ invoke__">createEditor</span>(obj, id, opt, ready);</div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="22"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line">  };</div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="23"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line">  <span class="hljs-function"><span class="hljs-keyword">function</span> <span class="hljs-title">createEditor</span>(<span class="hljs-params">obj, id, opt, ready</span>) </span>{</div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="24"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line">    obj.<span class="hljs-title function_ invoke__">attr</span>(<span class="hljs-string">'id'</span>, id);</div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="25"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line">    <span class="hljs-keyword">var</span> editor = UE.<span class="hljs-title function_ invoke__">getEditor</span>(id, opt);</div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="26"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line">    editor.<span class="hljs-title function_ invoke__">ready</span>(function() {</div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="27"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line">      <span class="hljs-title function_ invoke__">ready</span>(editor);</div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="28"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line">    });</div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="29"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line">    <span class="hljs-keyword">return</span> editor;</div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="30"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line">  }</div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="31"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line">}(jQuery, main));</div></div></li></ol></code><div class="hljs-button {2}" data-title="复制" onclick="hljs.copyCode(event)"></div></pre> 
<p>（2）在<strong>add.blade.php</strong>文件中引入编辑器相关的文件，具体代码如下：</p> 
<pre data-index="93" class="set-code-show" name="code"><code class="language-php hljs"><ol class="hljs-ln" style="width:100%"><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="1"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line">&lt;script src=<span class="hljs-string">"{{asset('admin')}}/common/editor/ueditor1.4.3.3/ueditor.config.js"</span>&gt;&lt;/script&gt;</div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="2"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line">&lt;script src=<span class="hljs-string">"{{asset('admin')}}/common/editor/ueditor1.4.3.3/ueditor.all.min.js"</span>&gt;&lt;/script&gt;</div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="3"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line">&lt;script src=<span class="hljs-string">"{{asset('admin')}}/common/editor/main.editor.js"</span>&gt;&lt;/script&gt;</div></div></li></ol></code><div class="hljs-button {2}" data-title="复制" onclick="hljs.copyCode(event)"></div></pre> 
<h4 id="5.%E6%98%BE%E7%A4%BA%E5%86%85%E5%AE%B9%E5%88%97%E8%A1%A8"><a name="t25"></a>5.显示内容列表</h4> 
<p>（1）在<strong>Content</strong>控制器中编写<strong>index()</strong>方法，具体代码如下：</p> 
<pre data-index="94" class="set-code-show" name="code"><code class="language-php hljs"><ol class="hljs-ln" style="width:100%"><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="1"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line"><span class="hljs-keyword">public</span> <span class="hljs-function"><span class="hljs-keyword">function</span> <span class="hljs-title">index</span>(<span class="hljs-params"><span class="hljs-variable">$id</span> = <span class="hljs-number">0</span></span>)</span></div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="2"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line">    {</div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="3"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line">        <span class="hljs-variable">$data</span> = <span class="hljs-title class_">Category</span>::<span class="hljs-title function_ invoke__">orderBy</span>(<span class="hljs-string">'sort'</span>, <span class="hljs-string">'asc'</span>)-&gt;<span class="hljs-title function_ invoke__">get</span>()-&gt;<span class="hljs-title function_ invoke__">toArray</span>();</div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="4"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line">        <span class="hljs-variable">$cate</span> = <span class="hljs-keyword">new</span> <span class="hljs-title class_">CategoryController</span>();</div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="5"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line">        <span class="hljs-variable">$category</span> = <span class="hljs-variable">$cate</span>-&gt;<span class="hljs-title function_ invoke__">getTreeListCheckLeaf</span>(<span class="hljs-variable">$data</span>);</div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="6"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line">        <span class="hljs-variable">$content</span> = <span class="hljs-title class_">Content</span>::<span class="hljs-title function_ invoke__">get</span>();</div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="7"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line">        <span class="hljs-keyword">if</span> (<span class="hljs-variable">$id</span>) {</div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="8"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line">            <span class="hljs-variable">$content</span> = <span class="hljs-title class_">Content</span>::<span class="hljs-title function_ invoke__">where</span>(<span class="hljs-string">'cid'</span>, <span class="hljs-variable">$id</span>)-&gt;<span class="hljs-title function_ invoke__">get</span>();</div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="9"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line">        }</div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="10"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line">        <span class="hljs-keyword">return</span> <span class="hljs-title function_ invoke__">view</span>(<span class="hljs-string">'admin.content.index'</span>, [<span class="hljs-string">'category'</span> =&gt; <span class="hljs-variable">$category</span>, <span class="hljs-string">'content'</span> =&gt; <span class="hljs-variable">$content</span>, <span class="hljs-string">'cid'</span> =&gt; <span class="hljs-variable">$id</span>]);</div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="11"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line">    }</div></div></li></ol></code><div class="hljs-button {2}" data-title="复制" onclick="hljs.copyCode(event)"></div></pre> 
<p>（2）在展示内容时，需显示内容对应的栏目，因此在Content模型中添加关联模型，具体代码如下：</p> 
<pre data-index="95" class="set-code-show" name="code"><code class="language-php hljs"><ol class="hljs-ln" style="width:100%"><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="1"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line"><span class="hljs-keyword">public</span> <span class="hljs-function"><span class="hljs-keyword">function</span> <span class="hljs-title">category</span>(<span class="hljs-params"></span>)</span></div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="2"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line">    {</div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="3"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line">        <span class="hljs-keyword">return</span> <span class="hljs-variable language_">$this</span>-&gt;<span class="hljs-title function_ invoke__">belongsTo</span>(<span class="hljs-string">'App\Category'</span>, <span class="hljs-string">'cid'</span>, <span class="hljs-string">'id'</span>);</div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="4"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line">    }</div></div></li></ol></code><div class="hljs-button {2}" data-title="复制" onclick="hljs.copyCode(event)"></div></pre> 
<p>（3）创建<strong>resources\views\admin\content\index.blade.php</strong>文件，具体代码如下：</p> 
<pre data-index="96" class="set-code-show" name="code"><code class="language-php hljs"><ol class="hljs-ln" style="width:1244px"><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="1"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line">@<span class="hljs-keyword">extends</span>(<span class="hljs-string">'admin/layouts/admin'</span>)</div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="2"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line">@<span class="hljs-title function_ invoke__">section</span>(<span class="hljs-string">'title'</span>, <span class="hljs-string">'内容列表'</span>)</div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="3"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line">@<span class="hljs-title function_ invoke__">section</span>(<span class="hljs-string">'main'</span>)</div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="4"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line">  &lt;div <span class="hljs-class"><span class="hljs-class"><span class="hljs-keyword">class</span>="<span class="hljs-title">main</span>-<span class="hljs-title">title</span>"&gt;&lt;<span class="hljs-title">h2</span>&gt;内容管理&lt;/<span class="hljs-title">h2</span>&gt;&lt;/<span class="hljs-title">div</span>&gt;</span></span></div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="5"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line"><span class="hljs-class">  &lt;<span class="hljs-title">div</span> <span class="hljs-title">class</span>="<span class="hljs-title">main</span>-<span class="hljs-title">section</span> <span class="hljs-title">form</span>-<span class="hljs-title">inline</span>"&gt;</span></div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="6"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line"><span class="hljs-class">    &lt;<span class="hljs-title">a</span> <span class="hljs-title">href</span>="</span>{{ <span class="hljs-title function_ invoke__">url</span>(<span class="hljs-string">'content/add'</span>) }}<span class="hljs-string">" class="</span>btn btn-success<span class="hljs-string"><span class="hljs-string">"&gt;+ 新增&lt;/a&gt;</span></span></div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="7"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line"><span class="hljs-string">    &lt;!-- 此处编写分类下拉菜单 --&gt;</span></div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="8"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line"><span class="hljs-string">    &lt;select class="</span>j-select form-control<span class="hljs-string">" style="</span>min-width:<span class="hljs-number">120</span>px;margin-left:<span class="hljs-number">8</span>px<span class="hljs-string"><span class="hljs-string">"&gt;</span></span></div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="9"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line"><span class="hljs-string">      &lt;option value="</span>{{ <span class="hljs-title function_ invoke__">url</span>(<span class="hljs-string">'content'</span>, [<span class="hljs-string">'id'</span> =&gt; <span class="hljs-number">0</span>]) }}<span class="hljs-string"><span class="hljs-string">"&gt;所有分类&lt;/option&gt;</span></span></div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="10"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line"><span class="hljs-string">      @foreach(<span class="hljs-subst">$category</span> as <span class="hljs-subst">$v</span>)</span></div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="11"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line"><span class="hljs-string">        @if(<span class="hljs-subst">$v</span>['level'])</span></div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="12"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line"><span class="hljs-string">        &lt;option value="</span>{{ <span class="hljs-title function_ invoke__">url</span>(<span class="hljs-string">'content'</span>, [<span class="hljs-string">'d'</span> =&gt; <span class="hljs-variable">$v</span>[<span class="hljs-string">'id'</span>]]) }}<span class="hljs-string">" data-id="</span>{{<span class="hljs-variable">$v</span>[<span class="hljs-string">'id'</span>]}}<span class="hljs-string"><span class="hljs-string">"&gt;</span></span></div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="13"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line"><span class="hljs-string">          &lt;small class="</span>text-muted<span class="hljs-string"><span class="hljs-string">"&gt;--&lt;/small&gt; {<span class="hljs-subst">{$v['name']}</span>}</span></span></div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="14"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line"><span class="hljs-string">        &lt;/option&gt;</span></div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="15"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line"><span class="hljs-string">        @else</span></div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="16"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line"><span class="hljs-string">        &lt;option value="</span>{{ <span class="hljs-title function_ invoke__">url</span>(<span class="hljs-string">'content'</span>, [<span class="hljs-string">'id'</span> =&gt; <span class="hljs-variable">$v</span>[<span class="hljs-string">'id'</span>]]) }}<span class="hljs-string">" data-id="</span>{{<span class="hljs-variable">$v</span>[<span class="hljs-string">'id'</span>]}}<span class="hljs-string"><span class="hljs-string">"&gt;</span></span></div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="17"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line"><span class="hljs-string">          {<span class="hljs-subst">{$v['name']}</span>}</span></div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="18"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line"><span class="hljs-string">        &lt;/option&gt;</span></div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="19"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line"><span class="hljs-string">        @endif</span></div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="20"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line"><span class="hljs-string">      @endforeach</span></div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="21"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line"><span class="hljs-string">    &lt;/select&gt;</span></div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="22"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line"><span class="hljs-string">  &lt;/div&gt;</span></div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="23"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line"><span class="hljs-string">  &lt;div class="</span>main-section<span class="hljs-string"><span class="hljs-string">"&gt;</span></span></div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="24"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line"><span class="hljs-string">    &lt;form method="</span>post<span class="hljs-string">" action="</span>{{ <span class="hljs-title function_ invoke__">url</span>(<span class="hljs-string">'category/sort'</span>)}}<span class="hljs-string">" class="</span>j-form<span class="hljs-string"><span class="hljs-string">"&gt;</span></span></div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="25"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line"><span class="hljs-string">      &lt;table class="</span>table table-striped table-bordered table-hover<span class="hljs-string"><span class="hljs-string">"&gt;</span></span></div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="26"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line"><span class="hljs-string">        &lt;thead&gt;</span></div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="27"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line"><span class="hljs-string">        &lt;tr&gt;</span></div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="28"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line"><span class="hljs-string">          &lt;th width="</span><span class="hljs-number">75</span><span class="hljs-string"><span class="hljs-string">"&gt;序号&lt;/th&gt;&lt;th&gt;分类&lt;/th&gt;&lt;th&gt;图片&lt;/th&gt;&lt;th&gt;标题&lt;/th&gt;</span></span></div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="29"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line"><span class="hljs-string">          &lt;th&gt;状态&lt;/th&gt;&lt;th&gt;创建时间&lt;/th&gt;&lt;th width="</span><span class="hljs-number">100</span><span class="hljs-string"><span class="hljs-string">"&gt;操作&lt;/th&gt;</span></span></div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="30"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line"><span class="hljs-string">        &lt;/tr&gt;</span></div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="31"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line"><span class="hljs-string">        &lt;/thead&gt;</span></div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="32"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line"><span class="hljs-string">        &lt;tbody&gt;</span></div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="33"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line"><span class="hljs-string">        @foreach(<span class="hljs-subst">$content</span> as <span class="hljs-subst">$v</span>)</span></div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="34"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line"><span class="hljs-string">          &lt;!-- 此处编写内容列表代码 --&gt;</span></div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="35"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line"><span class="hljs-string">          &lt;tr class="</span>j-pid-{{ <span class="hljs-variable">$v</span>-&gt;pid }}<span class="hljs-string">" @if(<span class="hljs-subst">$v</span>-&gt;level)style="</span>display:none<span class="hljs-string"><span class="hljs-string">"@endif&gt;</span></span></div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="36"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line"><span class="hljs-string">            &lt;td&gt;{{ <span class="hljs-subst">$v</span>-&gt;id }}&lt;/td&gt;</span></div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="37"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line"><span class="hljs-string">            &lt;td&gt;{{ <span class="hljs-subst">$v</span>-&gt;category-&gt;name}}&lt;/td&gt;</span></div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="38"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line"><span class="hljs-string">            &lt;td&gt;&lt;img @if(<span class="hljs-subst">$v</span>-&gt;image) src="</span>/<span class="hljs-built_in">static</span>/upload/{{ <span class="hljs-variable">$v</span>-&gt;image}}<span class="hljs-string">" @else src="</span>{{<span class="hljs-title function_ invoke__">asset</span>(<span class="hljs-string">'admin'</span>)}}/img/noimg.png<span class="hljs-string">" @endif width="</span><span class="hljs-number">50</span><span class="hljs-string">" height="</span><span class="hljs-number">50</span><span class="hljs-string"><span class="hljs-string">"&gt;&lt;/td&gt;</span></span></div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="39"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line"><span class="hljs-string">            &lt;td&gt;{{ <span class="hljs-subst">$v</span>-&gt;title }}&lt;/td&gt;</span></div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="40"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line"><span class="hljs-string">            &lt;td&gt;@if(<span class="hljs-subst">$v</span>-&gt;status==1) 默认  @else 推荐 @endif&lt;/td&gt;</span></div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="41"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line"><span class="hljs-string">            &lt;td&gt;{{ <span class="hljs-subst">$v</span>-&gt;created_at }}&lt;/td&gt;</span></div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="42"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line"><span class="hljs-string">            &lt;td&gt;&lt;a href="</span>{{ <span class="hljs-title function_ invoke__">url</span>(<span class="hljs-string">'content/edit'</span>, [<span class="hljs-string">'id'</span> =&gt; <span class="hljs-variable">$v</span>-&gt;id ]) }}<span class="hljs-string">" style="</span>margin-right:<span class="hljs-number">5</span>px;<span class="hljs-string"><span class="hljs-string">"&gt;编辑&lt;/a&gt;</span></span></div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="43"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line"><span class="hljs-string">              &lt;a href="</span>{{ <span class="hljs-title function_ invoke__">url</span>(<span class="hljs-string">'content/delete'</span>, [<span class="hljs-string">'id'</span> =&gt; <span class="hljs-variable">$v</span>-&gt;id ]) }}<span class="hljs-string">" class="</span>j-del text-danger<span class="hljs-string"><span class="hljs-string">"&gt;删除&lt;/a&gt;</span></span></div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="44"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line"><span class="hljs-string">            &lt;/td&gt;</span></div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="45"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line"><span class="hljs-string">          &lt;/tr&gt;</span></div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="46"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line"><span class="hljs-string">        @endforeach</span></div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="47"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line"><span class="hljs-string">        @if(empty(<span class="hljs-subst">$content</span>))</span></div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="48"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line"><span class="hljs-string">          &lt;tr&gt;&lt;td colspan="</span><span class="hljs-number">7</span><span class="hljs-string">" class="</span>text-center<span class="hljs-string"><span class="hljs-string">"&gt;还没有添加内容&lt;/td&gt;&lt;/tr&gt;</span></span></div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="49"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line"><span class="hljs-string">        @endif</span></div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="50"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line"><span class="hljs-string">        &lt;/tbody&gt;</span></div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="51"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line"><span class="hljs-string">      &lt;/table&gt;</span></div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="52"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line"><span class="hljs-string">      {{csrf_field()}}</span></div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="53"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line"><span class="hljs-string">    &lt;/form&gt;</span></div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="54"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line"><span class="hljs-string">  &lt;/div&gt;</span></div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="55"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line"><span class="hljs-string">  &lt;script&gt;</span></div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="56"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line"><span class="hljs-string">    main.menuActive('content');</span></div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="57"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line"><span class="hljs-string">    $('.j-select').change(function() {</span></div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="58"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line"><span class="hljs-string">      location.href = $(this).val();</span></div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="59"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line"><span class="hljs-string">    });</span></div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="60"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line"><span class="hljs-string">    $('option[data-id=' + {<span class="hljs-subst">{$cid}</span>} + ']').attr('selected', true);</span></div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="61"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line"><span class="hljs-string">    $('.j-del').click(function() {</span></div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="62"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line"><span class="hljs-string">      if (confirm('您确定要删除此项？')) {</span></div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="63"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line"><span class="hljs-string">        var data = { _token: '{{ csrf_token() }}' };</span></div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="64"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line"><span class="hljs-string">        main.ajaxPost({url:$(this).attr('href'), data: data}, function(){</span></div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="65"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line"><span class="hljs-string">          location.reload();</span></div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="66"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line"><span class="hljs-string">        });</span></div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="67"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line"><span class="hljs-string">      }</span></div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="68"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line"><span class="hljs-string">      return false;</span></div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="69"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line"><span class="hljs-string">    });</span></div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="70"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line"><span class="hljs-string">  &lt;/script&gt;</span></div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="71"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line"><span class="hljs-string">@endsection</span></div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="72"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line"><span class="hljs-string"></span></div></div></li></ol></code><div class="hljs-button {2}" data-title="复制" onclick="hljs.copyCode(event)"></div></pre> 
<p>（4）在<strong>routes\web.php</strong>文件中添加内容列表页的路由，具体代码如下：</p> 
<pre data-index="97" class="set-code-show" name="code"><code class="language-php hljs">    <span class="hljs-title class_">Route</span>::<span class="hljs-title function_ invoke__">get</span>(<span class="hljs-string">'{id?}'</span>, <span class="hljs-string">'ContentController@index'</span>);
</code><div class="hljs-button {2}" data-title="复制" onclick="hljs.copyCode(event)"></div></pre> 
<h4 id="6.%E7%BC%96%E8%BE%91%E5%86%85%E5%AE%B9"><a name="t26"></a>6.编辑内容</h4> 
<p>（1）在内容列表页中为“编辑”按钮添加链接，具体代码如下：</p> 
<pre data-index="98" class="set-code-show" name="code"><code class="language-php hljs">&lt;a href=<span class="hljs-string">"{{ url('content/edit', ['id' =&gt; <span class="hljs-subst">$v</span>-&gt;id ]) }}"</span> style=<span class="hljs-string">"margin-right:5px;"</span>&gt;编辑&lt;/a&gt;
</code><div class="hljs-button {2}" data-title="复制" onclick="hljs.copyCode(event)"></div></pre> 
<p>（2）在<strong>Content</strong>控制器中添加<strong>edit()</strong>方法，具体代码如下：</p> 
<pre data-index="99" class="set-code-show" name="code"><code class="language-php hljs"><ol class="hljs-ln" style="width:100%"><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="1"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line"> <span class="hljs-keyword">public</span> <span class="hljs-function"><span class="hljs-keyword">function</span> <span class="hljs-title">edit</span>(<span class="hljs-params">Request <span class="hljs-variable">$request</span></span>)</span></div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="2"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line">    {</div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="3"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line">        <span class="hljs-variable">$id</span> = <span class="hljs-variable">$request</span>-&gt;id;</div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="4"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line">        <span class="hljs-variable">$data</span> = <span class="hljs-title class_">Category</span>::<span class="hljs-title function_ invoke__">orderBy</span>(<span class="hljs-string">'sort'</span>, <span class="hljs-string">'asc'</span>)-&gt;<span class="hljs-title function_ invoke__">get</span>()-&gt;<span class="hljs-title function_ invoke__">toArray</span>();</div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="5"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line">        <span class="hljs-variable">$cate</span> = <span class="hljs-keyword">new</span> <span class="hljs-title class_">CategoryController</span>();</div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="6"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line">        <span class="hljs-variable">$category</span> = <span class="hljs-variable">$cate</span>-&gt;<span class="hljs-title function_ invoke__">getTreeListCheckLeaf</span>(<span class="hljs-variable">$data</span>);</div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="7"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line">        <span class="hljs-variable">$content</span> = <span class="hljs-title class_">Content</span>::<span class="hljs-title function_ invoke__">find</span>(<span class="hljs-variable">$id</span>);</div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="8"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line">        <span class="hljs-keyword">return</span> <span class="hljs-title function_ invoke__">view</span>(<span class="hljs-string">'admin.content.edit'</span>, [<span class="hljs-string">'category'</span> =&gt; <span class="hljs-variable">$category</span>, <span class="hljs-string">'content'</span> =&gt; <span class="hljs-variable">$content</span>]);</div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="9"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line">    }</div></div></li></ol></code><div class="hljs-button {2}" data-title="复制" onclick="hljs.copyCode(event)"></div></pre> 
<p>（3）在<strong>routes\web.php</strong>文件中添加内容列表页的路由，具体代码如下：</p> 
<pre data-index="100" class="set-code-show" name="code"><code class="language-php hljs">    <span class="hljs-title class_">Route</span>::<span class="hljs-title function_ invoke__">get</span>(<span class="hljs-string">'edit/{id}'</span>, <span class="hljs-string">'ContentController@edit'</span>);
</code><div class="hljs-button {2}" data-title="复制" onclick="hljs.copyCode(event)"></div></pre> 
<h4 id="7.%E5%88%A0%E9%99%A4%E5%86%85%E5%AE%B9"><a name="t27"></a>7.删除内容</h4> 
<p>（1）在内容列表页为“删除”按钮添加链接，具体代码如下：</p> 
<pre data-index="101" class="set-code-show" name="code"><code class="language-php hljs"><ol class="hljs-ln" style="width:100%"><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="1"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line">&lt;a href=<span class="hljs-string">"{{ url('content/delete', ['id' =&gt; <span class="hljs-subst">$v</span>-&gt;id ]) }}"</span> <span class="hljs-class"><span class="hljs-keyword">class</span>="<span class="hljs-title">j</span>-<span class="hljs-title">del</span> <span class="hljs-title">text</span>-<span class="hljs-title">danger</span>"&gt;删除&lt;/<span class="hljs-title">a</span>&gt;</span></div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="2"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line"></div></div></li></ol></code><div class="hljs-button {2}" data-title="复制" onclick="hljs.copyCode(event)"></div></pre> 
<p>（2）在<strong>routes\web.php</strong>文件中添加删除内容的路由，具体代码如下：</p> 
<pre data-index="102" class="set-code-show" name="code"><code class="language-php hljs">    <span class="hljs-title class_">Route</span>::<span class="hljs-title function_ invoke__">post</span>(<span class="hljs-string">'delete/{id}'</span>, <span class="hljs-string">'ContentController@delete'</span>);
</code><div class="hljs-button {2}" data-title="复制" onclick="hljs.copyCode(event)"></div></pre> 
<p>（3）在<strong>Content</strong>控制器中添加<strong>delete()</strong>方法，具体代码如下：</p> 
<pre data-index="103" class="set-code-show" name="code"><code class="language-php hljs"><ol class="hljs-ln" style="width:100%"><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="1"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line"> <span class="hljs-keyword">public</span> <span class="hljs-function"><span class="hljs-keyword">function</span> <span class="hljs-title">delete</span>(<span class="hljs-params"><span class="hljs-variable">$id</span></span>)</span></div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="2"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line">    {</div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="3"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line">        <span class="hljs-keyword">if</span> (!<span class="hljs-variable">$content</span> = <span class="hljs-title class_">Content</span>::<span class="hljs-title function_ invoke__">find</span>(<span class="hljs-variable">$id</span>)) {</div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="4"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line">            <span class="hljs-keyword">return</span> <span class="hljs-title function_ invoke__">response</span>()-&gt;<span class="hljs-title function_ invoke__">json</span>([<span class="hljs-string">'code'</span> =&gt; <span class="hljs-number">0</span>, <span class="hljs-string">'msg'</span> =&gt; <span class="hljs-string">'删除失败，记录不存在。'</span> ]);</div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="5"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line">        }</div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="6"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line">        <span class="hljs-variable">$content</span>-&gt;<span class="hljs-title function_ invoke__">delete</span>();</div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="7"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line">        <span class="hljs-keyword">return</span> <span class="hljs-title function_ invoke__">response</span>()-&gt;<span class="hljs-title function_ invoke__">json</span>([<span class="hljs-string">'code'</span> =&gt; <span class="hljs-number">1</span>, <span class="hljs-string">'msg'</span> =&gt; <span class="hljs-string">'删除成功'</span> ]);</div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="8"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line">    }</div></div></li></ol></code><div class="hljs-button {2}" data-title="复制" onclick="hljs.copyCode(event)"></div></pre> 
<h3 id="%E4%BA%94.%E5%B9%BF%E5%91%8A%E4%BD%8D%E7%AE%A1%E7%90%86"><a name="t28"></a>五.广告位管理</h3> 
<h4 id="1.%E5%88%9B%E5%BB%BA%E5%B9%BF%E5%91%8A%E4%BD%8D%E8%A1%A8"><a name="t29"></a>1.创建广告位表</h4> 
<p>（1）创建广告位表对应的迁移文件后，在迁移文件的up()方法中添加表结构信息，具体代码如下：</p> 
<pre data-index="104" class="set-code-show" name="code"><code class="language-php hljs"><ol class="hljs-ln" style="width:100%"><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="1"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line"> <span class="hljs-keyword">public</span> <span class="hljs-function"><span class="hljs-keyword">function</span> <span class="hljs-title">up</span>(<span class="hljs-params"></span>)</span></div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="2"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line">    {</div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="3"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line">        <span class="hljs-title class_">Schema</span>::<span class="hljs-title function_ invoke__">create</span>(<span class="hljs-string">'adv'</span>, function (Blueprint <span class="hljs-variable">$table</span>) {</div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="4"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line">            <span class="hljs-variable">$table</span>-&gt;<span class="hljs-title function_ invoke__">increments</span>(<span class="hljs-string">'id'</span>)-&gt;<span class="hljs-title function_ invoke__">comment</span>(<span class="hljs-string">'主键'</span>);</div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="5"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line">            <span class="hljs-variable">$table</span>-&gt;<span class="hljs-keyword">string</span>(<span class="hljs-string">'name'</span>, <span class="hljs-number">32</span>)-&gt;<span class="hljs-title function_ invoke__">comment</span>(<span class="hljs-string">'广告位名称'</span>);</div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="6"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line">            <span class="hljs-variable">$table</span>-&gt;<span class="hljs-title function_ invoke__">timestamps</span>();</div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="7"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line">        });</div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="8"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line">    }</div></div></li></ol></code><div class="hljs-button {2}" data-title="复制" onclick="hljs.copyCode(event)"></div></pre> 
<p>（2）创建广告位表对应的模型文件，具体代码如下：</p> 
<pre data-index="105" class="set-code-show" name="code"><code class="language-php hljs">php artisan make:model Adv</code><div class="hljs-button {2}" data-title="复制" onclick="hljs.copyCode(event)"></div></pre> 
<p>（3）执行上述命令后，会自动创建<strong>app\Adv.php</strong>文件，具体代码如下：</p> 
<pre data-index="106" class="set-code-show" name="code"><code class="language-php hljs"><ol class="hljs-ln" style="width:100%"><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="1"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line"><span class="hljs-meta">&lt;?php</span></div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="2"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line"> </div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="3"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line"><span class="hljs-keyword">namespace</span> <span class="hljs-title class_">App</span>;</div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="4"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line"> </div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="5"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line"><span class="hljs-keyword">use</span> <span class="hljs-title">Illuminate</span>\<span class="hljs-title">Database</span>\<span class="hljs-title">Eloquent</span>\<span class="hljs-title">Model</span>;</div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="6"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line"> </div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="7"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line"><span class="hljs-class"><span class="hljs-keyword">class</span> <span class="hljs-title">Adv</span> <span class="hljs-keyword">extends</span> <span class="hljs-title">Model</span></span></div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="8"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line">{</div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="9"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line">    <span class="hljs-keyword">protected</span> <span class="hljs-variable">$table</span> = <span class="hljs-string">"adv"</span>;</div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="10"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line">    <span class="hljs-keyword">public</span> <span class="hljs-variable">$fillable</span> = [<span class="hljs-string">'name'</span>];</div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="11"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line">}</div></div></li></ol></code><div class="hljs-button {2}" data-title="复制" onclick="hljs.copyCode(event)"></div></pre> 
<h4 id="2.%E6%B7%BB%E5%8A%A0%E5%B9%BF%E5%91%8A%E4%BD%8D"><a name="t30"></a>2.添加广告位</h4> 
<p>（1）创建<strong>Adv</strong>控制器，具体代码如下：</p> 
<pre data-index="107" class="set-code-show" name="code"><code class="language-php hljs">php artisan make:controller Admin\AdvController</code><div class="hljs-button {2}" data-title="复制" onclick="hljs.copyCode(event)"></div></pre> 
<p>（2）在控制器中添加<strong>add()</strong>方法用于实现添加广告位的功能，添加<strong>save()</strong>方法用于保存添加的广告位，具体代码如下：</p> 
<pre data-index="108" class="set-code-show" name="code"><code class="language-php hljs"><ol class="hljs-ln" style="width:100%"><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="1"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line">  <span class="hljs-keyword">public</span> <span class="hljs-function"><span class="hljs-keyword">function</span> <span class="hljs-title">add</span>(<span class="hljs-params"><span class="hljs-variable">$id</span> = <span class="hljs-number">0</span></span>)</span>{</div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="2"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line">        <span class="hljs-variable">$data</span> = [];</div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="3"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line">        <span class="hljs-keyword">if</span>(<span class="hljs-variable">$id</span> &gt; <span class="hljs-number">0</span>){</div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="4"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line">            <span class="hljs-variable">$data</span> = <span class="hljs-title class_">Adv</span>::<span class="hljs-title function_ invoke__">find</span>(<span class="hljs-variable">$id</span>);</div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="5"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line">        }</div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="6"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line">        <span class="hljs-keyword">return</span> <span class="hljs-title function_ invoke__">view</span>(<span class="hljs-string">'admin.adv.add'</span>, [<span class="hljs-string">'data'</span> =&gt; <span class="hljs-variable">$data</span>]);</div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="7"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line">    }</div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="8"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line"> </div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="9"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line">    <span class="hljs-keyword">public</span> <span class="hljs-function"><span class="hljs-keyword">function</span> <span class="hljs-title">save</span>(<span class="hljs-params">Request <span class="hljs-variable">$request</span></span>)</span>{</div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="10"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line">        <span class="hljs-variable">$data</span> = <span class="hljs-variable">$request</span>-&gt;<span class="hljs-title function_ invoke__">all</span>();</div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="11"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line"> </div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="12"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line">        <span class="hljs-variable language_">$this</span>-&gt;<span class="hljs-title function_ invoke__">validate</span>(<span class="hljs-variable">$request</span>,[</div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="13"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line">            <span class="hljs-string">'name'</span>=&gt;<span class="hljs-string">'required'</span></div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="14"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line">        ],[</div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="15"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line">            <span class="hljs-string">'name.require'</span>=&gt;<span class="hljs-string">'名称不能为空'</span></div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="16"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line">        ]);</div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="17"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line">        <span class="hljs-keyword">if</span>(<span class="hljs-keyword">isset</span>(<span class="hljs-variable">$data</span>[<span class="hljs-string">'id'</span>])){</div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="18"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line">            <span class="hljs-variable">$id</span> = <span class="hljs-variable">$data</span>[<span class="hljs-string">'id'</span>];</div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="19"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line">            <span class="hljs-keyword">unset</span>(<span class="hljs-variable">$data</span>[<span class="hljs-string">'id'</span>]);</div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="20"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line">            <span class="hljs-keyword">unset</span>(<span class="hljs-variable">$data</span>[<span class="hljs-string">'_token'</span>]);</div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="21"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line">            <span class="hljs-variable">$res</span> = <span class="hljs-title class_">Adv</span>::<span class="hljs-title function_ invoke__">where</span>(<span class="hljs-string">'id'</span>,<span class="hljs-variable">$id</span>)-&gt;<span class="hljs-title function_ invoke__">update</span>(<span class="hljs-variable">$data</span>);</div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="22"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line">            <span class="hljs-variable">$type</span> = <span class="hljs-variable">$res</span> ? <span class="hljs-string">"message"</span> : <span class="hljs-string">"tip"</span>;</div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="23"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line">            <span class="hljs-variable">$message</span> = <span class="hljs-variable">$res</span> ? <span class="hljs-string">"修改成功"</span> : <span class="hljs-string">"修改失败"</span>;</div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="24"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line">            <span class="hljs-keyword">return</span> <span class="hljs-title function_ invoke__">redirect</span>(<span class="hljs-string">'adv'</span>)-&gt;<span class="hljs-title function_ invoke__">with</span>(<span class="hljs-variable">$type</span>, <span class="hljs-variable">$message</span>);</div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="25"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line">        }</div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="26"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line"> </div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="27"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line">        <span class="hljs-variable">$re</span> = <span class="hljs-title class_">Adv</span>::<span class="hljs-title function_ invoke__">create</span>(<span class="hljs-variable">$data</span>);</div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="28"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line">        <span class="hljs-keyword">if</span>(<span class="hljs-variable">$re</span>){</div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="29"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line">            <span class="hljs-keyword">return</span> <span class="hljs-title function_ invoke__">redirect</span>(<span class="hljs-string">'adv'</span>)-&gt;<span class="hljs-title function_ invoke__">with</span>(<span class="hljs-string">'message'</span>,<span class="hljs-string">'添加成功'</span>);</div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="30"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line">        }<span class="hljs-keyword">else</span>{</div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="31"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line">            <span class="hljs-keyword">return</span> <span class="hljs-title function_ invoke__">redirect</span>(<span class="hljs-string">'adv/add'</span>)-&gt;<span class="hljs-title function_ invoke__">with</span>(<span class="hljs-string">'tip'</span>,<span class="hljs-string">'添加失败'</span>);</div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="32"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line">        }</div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="33"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line">    }</div></div></li></ol></code><div class="hljs-button {2}" data-title="复制" onclick="hljs.copyCode(event)"></div></pre> 
<p>（3）在控制器中引入Adv的命名空间。具体代码如下：</p> 
<pre data-index="109" class="set-code-show" name="code"><code class="language-php hljs"><span class="hljs-keyword">use</span> <span class="hljs-title">App</span>\<span class="hljs-title">Adv</span>;
</code><div class="hljs-button {2}" data-title="复制" onclick="hljs.copyCode(event)"></div></pre> 
<p>（4）在<strong>routes\web.php</strong>中添加广告位管理的路由组，具体代码如下：</p> 
<pre data-index="110" class="set-code-show" name="code"><code class="language-php hljs"><ol class="hljs-ln" style="width:100%"><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="1"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line"><span class="hljs-comment">//广告</span></div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="2"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line"><span class="hljs-title class_">Route</span>::<span class="hljs-title function_ invoke__">prefix</span>(<span class="hljs-string">'adv'</span>)-&gt;<span class="hljs-title function_ invoke__">namespace</span>(<span class="hljs-string">'Admin'</span>)-&gt;<span class="hljs-title function_ invoke__">middleware</span>([<span class="hljs-string">'Admin'</span>])-&gt;<span class="hljs-title function_ invoke__">group</span>(function () {</div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="3"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line">    <span class="hljs-title class_">Route</span>::<span class="hljs-title function_ invoke__">get</span>(<span class="hljs-string">'add/{id?}'</span>, <span class="hljs-string">'AdvController@add'</span>);</div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="4"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line">    <span class="hljs-title class_">Route</span>::<span class="hljs-title function_ invoke__">post</span>(<span class="hljs-string">'save'</span>, <span class="hljs-string">'AdvController@save'</span>);</div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="5"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line">});</div></div></li></ol></code><div class="hljs-button {2}" data-title="复制" onclick="hljs.copyCode(event)"></div></pre> 
<h4 id="3.%E6%98%BE%E7%A4%BA%E3%80%81%E7%BC%96%E8%BE%91%E3%80%81%E5%88%A0%E9%99%A4%E5%B9%BF%E5%91%8A%E4%BD%8D%E5%88%97%E8%A1%A8"><a name="t31"></a>3.显示、编辑、删除广告位列表</h4> 
<p>(1)修改<strong>admin.blade.php</strong>，为广告位菜单项添加链接，具体代码如下：</p> 
<pre data-index="111" class="set-code-show" name="code"><code class="language-php hljs"><ol class="hljs-ln" style="width:100%"><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="1"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line">&lt;a href=<span class="hljs-string">"{{url('adv')}}"</span> data-name=<span class="hljs-string">"adv"</span>&gt;</div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="2"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line">    &lt;i <span class="hljs-class"><span class="hljs-keyword">class</span>="<span class="hljs-title">fa</span> <span class="hljs-title">fa</span>-<span class="hljs-title">list</span> <span class="hljs-title">fa</span>-<span class="hljs-title">fw</span>"&gt;&lt;/<span class="hljs-title">i</span>&gt;广告位&lt;/<span class="hljs-title">a</span>&gt;</span></div></div></li></ol></code><div class="hljs-button {2}" data-title="复制" onclick="hljs.copyCode(event)"></div></pre> 
<p>(2)在<strong>routes\web.php</strong>中添加广告位列表的路由，具体代码如下：</p> 
<pre data-index="112" class="set-code-show" name="code"><code class="language-php hljs"><ol class="hljs-ln" style="width:100%"><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="1"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line">    <span class="hljs-title class_">Route</span>::<span class="hljs-title function_ invoke__">get</span>(<span class="hljs-string">''</span>, <span class="hljs-string">'AdvController@index'</span>);</div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="2"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line">    route::<span class="hljs-title function_ invoke__">post</span>(<span class="hljs-string">'delete/{id}'</span>,<span class="hljs-string">'AdvController@delete'</span>);</div></div></li></ol></code><div class="hljs-button {2}" data-title="复制" onclick="hljs.copyCode(event)"></div></pre> 
<p>(3)在Adv控制器中编写<strong>index()</strong>方法和<strong>delete()</strong>方法，具体代码如下：</p> 
<pre data-index="113" class="set-code-show" name="code"><code class="language-php hljs"><ol class="hljs-ln" style="width:100%"><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="1"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line"><span class="hljs-keyword">public</span> <span class="hljs-function"><span class="hljs-keyword">function</span> <span class="hljs-title">index</span>(<span class="hljs-params"></span>)</span>{</div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="2"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line">        <span class="hljs-variable">$adv</span> = <span class="hljs-title class_">Adv</span>::<span class="hljs-title function_ invoke__">all</span>();</div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="3"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line">        <span class="hljs-keyword">return</span> <span class="hljs-title function_ invoke__">view</span>(<span class="hljs-string">'admin.adv.index'</span>, [<span class="hljs-string">'adv'</span> =&gt; <span class="hljs-variable">$adv</span>]);</div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="4"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line">    }</div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="5"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line"> </div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="6"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line"> <span class="hljs-keyword">public</span> <span class="hljs-function"><span class="hljs-keyword">function</span> <span class="hljs-title">delete</span>(<span class="hljs-params"><span class="hljs-variable">$id</span></span>)</span>{</div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="7"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line"> </div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="8"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line">        <span class="hljs-keyword">if</span> (!<span class="hljs-variable">$content</span> = <span class="hljs-title class_">Adv</span>::<span class="hljs-title function_ invoke__">find</span>(<span class="hljs-variable">$id</span>)) {</div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="9"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line">            <span class="hljs-keyword">return</span> <span class="hljs-title function_ invoke__">response</span>()-&gt;<span class="hljs-title function_ invoke__">json</span>([<span class="hljs-string">'code'</span> =&gt; <span class="hljs-number">0</span>, <span class="hljs-string">'msg'</span> =&gt; <span class="hljs-string">'删除失败，记录不存在。'</span> ]);</div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="10"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line">        }</div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="11"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line">        <span class="hljs-keyword">if</span>(<span class="hljs-title class_">Advcontent</span>::<span class="hljs-title function_ invoke__">where</span>(<span class="hljs-string">'advid'</span>, <span class="hljs-string">'='</span>, <span class="hljs-variable">$id</span>)-&gt;<span class="hljs-title function_ invoke__">exists</span>()){</div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="12"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line">            <span class="hljs-keyword">return</span> <span class="hljs-title function_ invoke__">response</span>()-&gt;<span class="hljs-title function_ invoke__">json</span>([<span class="hljs-string">'code'</span> =&gt; <span class="hljs-number">0</span>, <span class="hljs-string">'msg'</span> =&gt; <span class="hljs-string">'该广告位下有广告记录，请先删除广告内容。'</span> ]);</div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="13"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line">        }</div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="14"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line">        <span class="hljs-variable">$content</span>-&gt;<span class="hljs-title function_ invoke__">delete</span>();</div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="15"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line"> </div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="16"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line">        <span class="hljs-keyword">return</span> <span class="hljs-title function_ invoke__">response</span>()-&gt;<span class="hljs-title function_ invoke__">json</span>([<span class="hljs-string">'code'</span> =&gt; <span class="hljs-number">1</span>, <span class="hljs-string">'msg'</span> =&gt; <span class="hljs-string">'删除成功'</span> ]);</div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="17"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line">    }</div></div></li></ol></code><div class="hljs-button {2}" data-title="复制" onclick="hljs.copyCode(event)"></div></pre> 
<p>(4)创建<strong>index.blade.php</strong>文件，具体代码如下：</p> 
<pre data-index="114" class="set-code-show" name="code"><code class="language-php hljs"><ol class="hljs-ln" style="width:1206px"><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="1"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line">@<span class="hljs-keyword">extends</span>(<span class="hljs-string">'admin/layouts/admin'</span>)</div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="2"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line">@<span class="hljs-title function_ invoke__">section</span>(<span class="hljs-string">'title'</span>, <span class="hljs-string">'广告位列表'</span>)</div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="3"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line">@<span class="hljs-title function_ invoke__">section</span>(<span class="hljs-string">'main'</span>)</div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="4"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line">&lt;div <span class="hljs-class"><span class="hljs-class"><span class="hljs-keyword">class</span>="<span class="hljs-title">main</span>-<span class="hljs-title">title</span>"&gt;&lt;<span class="hljs-title">h2</span>&gt;广告位管理&lt;/<span class="hljs-title">h2</span>&gt;&lt;/<span class="hljs-title">div</span>&gt;</span></span></div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="5"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line"><span class="hljs-class">&lt;<span class="hljs-title">div</span> <span class="hljs-title">class</span>="<span class="hljs-title">main</span>-<span class="hljs-title">section</span> <span class="hljs-title">form</span>-<span class="hljs-title">inline</span>"&gt;</span></div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="6"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line"><span class="hljs-class">  &lt;<span class="hljs-title">a</span> <span class="hljs-title">href</span>="</span>{{ <span class="hljs-title function_ invoke__">url</span>(<span class="hljs-string">'adv/add'</span>) }}<span class="hljs-string">" class="</span>btn btn-success<span class="hljs-string"><span class="hljs-string">"&gt;+ 新增&lt;/a&gt;</span></span></div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="7"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line"><span class="hljs-string">&lt;/div&gt;</span></div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="8"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line"><span class="hljs-string">&lt;div class="</span>main-section<span class="hljs-string"><span class="hljs-string">"&gt;</span></span></div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="9"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line"><span class="hljs-string">  &lt;table class="</span>table table-striped table-bordered table-hover<span class="hljs-string"><span class="hljs-string">"&gt;</span></span></div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="10"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line"><span class="hljs-string">    &lt;thead&gt;</span></div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="11"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line"><span class="hljs-string">      &lt;tr&gt;</span></div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="12"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line"><span class="hljs-string">        &lt;th width="</span><span class="hljs-number">75</span><span class="hljs-string">"&gt;序号&lt;/th&gt;&lt;th&gt;广告位名称&lt;/th&gt;&lt;th width="</span><span class="hljs-number">100</span><span class="hljs-string"><span class="hljs-string">"&gt;操作&lt;/th&gt;</span></span></div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="13"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line"><span class="hljs-string">      &lt;/tr&gt;</span></div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="14"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line"><span class="hljs-string">    &lt;/thead&gt;</span></div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="15"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line"><span class="hljs-string">    &lt;tbody&gt;</span></div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="16"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line"><span class="hljs-string">      &lt;!-- 广告位列表--&gt;</span></div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="17"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line"><span class="hljs-string">      @foreach(<span class="hljs-subst">$adv</span> as <span class="hljs-subst">$v</span>)</span></div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="18"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line"><span class="hljs-string">      &lt;tr class="</span>j-pid-{{ <span class="hljs-variable">$v</span>[<span class="hljs-string">'pid'</span>] }}<span class="hljs-string"><span class="hljs-string">"&gt;</span></span></div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="19"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line"><span class="hljs-string">        &lt;td&gt;&lt;input type="</span>text<span class="hljs-string">" value="</span>{{<span class="hljs-variable">$v</span>-&gt;id}}<span class="hljs-string">" class="</span>form-control j-sort<span class="hljs-string">" maxlength="</span><span class="hljs-number">5</span><span class="hljs-string">" style="</span>height:<span class="hljs-number">25</span>px;font-size:<span class="hljs-number">12</span>px;padding:<span class="hljs-number">0</span> <span class="hljs-number">5</span>px;<span class="hljs-string"><span class="hljs-string">"&gt;&lt;/td&gt;</span></span></div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="20"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line"><span class="hljs-string">        &lt;td&gt;{<span class="hljs-subst">{$v-&gt;name}</span>}&lt;/td&gt;</span></div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="21"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line"><span class="hljs-string">        &lt;td&gt;</span></div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="22"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line"><span class="hljs-string">          &lt;a href="</span>{{ <span class="hljs-title function_ invoke__">url</span>(<span class="hljs-string">'adv/add'</span>, [<span class="hljs-string">'id'</span> =&gt; <span class="hljs-variable">$v</span>-&gt;id]) }}<span class="hljs-string">" style="</span>margin-right:<span class="hljs-number">5</span>px;<span class="hljs-string"><span class="hljs-string">"&gt;编辑&lt;/a&gt;</span></span></div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="23"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line"><span class="hljs-string">          &lt;a href="</span>{{ <span class="hljs-title function_ invoke__">url</span>(<span class="hljs-string">'adv/delete'</span>, [<span class="hljs-string">'id'</span> =&gt; <span class="hljs-variable">$v</span>-&gt;id]) }}<span class="hljs-string">" class="</span>j-del text-danger<span class="hljs-string"><span class="hljs-string">"&gt;删除&lt;/a&gt;</span></span></div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="24"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line"><span class="hljs-string">        &lt;/td&gt;</span></div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="25"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line"><span class="hljs-string">      &lt;/tr&gt;</span></div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="26"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line"><span class="hljs-string">      @endforeach</span></div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="27"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line"><span class="hljs-string">      @if(empty(<span class="hljs-subst">$adv</span>))</span></div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="28"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line"><span class="hljs-string">      &lt;tr&gt;&lt;td colspan="</span><span class="hljs-number">4</span><span class="hljs-string">" class="</span>text-center<span class="hljs-string"><span class="hljs-string">"&gt;还没有添加广告位&lt;/td&gt;&lt;/tr&gt;</span></span></div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="29"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line"><span class="hljs-string">      @endif</span></div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="30"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line"><span class="hljs-string">    &lt;/tbody&gt;</span></div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="31"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line"><span class="hljs-string">  &lt;/table&gt;</span></div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="32"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line"><span class="hljs-string">&lt;/div&gt;</span></div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="33"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line"><span class="hljs-string">&lt;script&gt;</span></div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="34"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line"><span class="hljs-string">main.menuActive('adv');</span></div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="35"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line"><span class="hljs-string">$('.j-del').click(function() {</span></div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="36"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line"><span class="hljs-string">    if (confirm('您确定要删除此项？')) {</span></div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="37"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line"><span class="hljs-string">    var data = { _token: '{{ csrf_token() }}' };</span></div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="38"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line"><span class="hljs-string">    main.ajaxPost({url:$(this).attr('href'), data: data}, function(){</span></div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="39"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line"><span class="hljs-string">        location.reload();</span></div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="40"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line"><span class="hljs-string">    });</span></div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="41"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line"><span class="hljs-string">    }</span></div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="42"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line"><span class="hljs-string">    return false;</span></div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="43"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line"><span class="hljs-string">});</span></div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="44"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line"><span class="hljs-string">&lt;/script&gt;</span></div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="45"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line"><span class="hljs-string">@endsection</span></div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="46"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line"><span class="hljs-string"></span></div></div></li></ol></code><div class="hljs-button {2}" data-title="复制" onclick="hljs.copyCode(event)"></div></pre> 
<p>(5)在浏览器访问，其效果如下图：</p> 
<p><img alt="" height="428" src="https://img-blog.csdnimg.cn/e30b6f8a9866413db6814ded829f023a.png" width="1200"></p> 
<p></p> 
<p>(6)通过浏览器访问，单机“删除”按钮删除广告位，查看广告位是否删除成功。</p> 
<h3 id="%E5%85%AD.%E5%B9%BF%E5%91%8A%E5%86%85%E5%AE%B9%E7%AE%A1%E7%90%86"><a name="t32"></a>六.广告内容管理</h3> 
<h4 id="1.%E5%88%9B%E5%BB%BA%E5%B9%BF%E5%91%8A%E5%86%85%E5%AE%B9%E8%A1%A8"><a name="t33"></a>1.创建广告内容表</h4> 
<p>(1)创建广告内容表的迁移文件，在迁移文件的<strong>up()</strong>方法中添加表结构信息，具体代码如下：</p> 
<pre data-index="115" class="set-code-show" name="code"><code class="language-php hljs"><ol class="hljs-ln" style="width:100%"><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="1"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line"><span class="hljs-keyword">public</span> <span class="hljs-function"><span class="hljs-keyword">function</span> <span class="hljs-title">up</span>(<span class="hljs-params"></span>)</span></div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="2"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line">    {</div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="3"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line">        <span class="hljs-title class_">Schema</span>::<span class="hljs-title function_ invoke__">create</span>(<span class="hljs-string">'adcontent'</span>, function (Blueprint <span class="hljs-variable">$table</span>) {</div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="4"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line">            <span class="hljs-variable">$table</span>-&gt;<span class="hljs-title function_ invoke__">increments</span>(<span class="hljs-string">'id'</span>)-&gt;<span class="hljs-title function_ invoke__">comment</span>(<span class="hljs-string">'主键'</span>);</div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="5"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line">            <span class="hljs-variable">$table</span>-&gt;<span class="hljs-keyword">integer</span>(<span class="hljs-string">'advid'</span>)-&gt;<span class="hljs-title function_ invoke__">comment</span>(<span class="hljs-string">'广告位id'</span>);</div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="6"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line">            <span class="hljs-variable">$table</span>-&gt;<span class="hljs-keyword">integer</span>(<span class="hljs-string">'path'</span>)-&gt;<span class="hljs-title function_ invoke__">comment</span>(<span class="hljs-string">'图片路径'</span>);</div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="7"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line">            <span class="hljs-variable">$table</span>-&gt;<span class="hljs-title function_ invoke__">timestamps</span>();</div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="8"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line">        });</div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="9"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line"> </div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="10"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line">    }</div></div></li></ol></code><div class="hljs-button {2}" data-title="复制" onclick="hljs.copyCode(event)"></div></pre> 
<p>(2)下面创建内容表对应的模型文件，具体代码如下：</p> 
<pre data-index="116" class="set-code-show" name="code"><code class="language-php hljs">php artisan make:model Advcontent</code><div class="hljs-button {2}" data-title="复制" onclick="hljs.copyCode(event)"></div></pre> 
<p>(3)执行上述命令后，会自动创建<strong>app\Advcontent.php</strong>文件，在文件中编写如下代码：</p> 
<pre data-index="117" class="set-code-show" name="code"><code class="language-php hljs"><ol class="hljs-ln" style="width:100%"><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="1"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line"><span class="hljs-meta">&lt;?php</span></div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="2"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line"> </div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="3"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line"><span class="hljs-keyword">namespace</span> <span class="hljs-title class_">App</span>;</div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="4"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line"> </div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="5"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line"><span class="hljs-keyword">use</span> <span class="hljs-title">Illuminate</span>\<span class="hljs-title">Database</span>\<span class="hljs-title">Eloquent</span>\<span class="hljs-title">Model</span>;</div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="6"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line"> </div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="7"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line"><span class="hljs-class"><span class="hljs-keyword">class</span> <span class="hljs-title">Advcontent</span> <span class="hljs-keyword">extends</span> <span class="hljs-title">Model</span></span></div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="8"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line">{</div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="9"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line">    <span class="hljs-keyword">protected</span> <span class="hljs-variable">$table</span> = <span class="hljs-string">"adcontent"</span>;</div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="10"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line">    <span class="hljs-keyword">public</span> <span class="hljs-variable">$fillable</span> = [<span class="hljs-string">'advid'</span>,<span class="hljs-string">'path'</span>];</div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="11"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line">}</div></div></li></ol></code><div class="hljs-button {2}" data-title="复制" onclick="hljs.copyCode(event)"></div></pre> 
<h4 id="2.%E6%B7%BB%E5%8A%A0%E3%80%81%E6%98%BE%E7%A4%BA%E3%80%81%E7%BC%96%E8%BE%91%E3%80%81%E5%88%A0%E9%99%A4%E5%B9%BF%E5%91%8A"><a name="t34"></a>2.添加、显示、编辑、删除广告</h4> 
<p>(1)创建<strong>Advcontent</strong>控制器，具体代码如下：</p> 
<pre data-index="118" class="set-code-show" name="code"><code class="language-php hljs">php artisan make:controller Admin\AdvcontentController</code><div class="hljs-button {2}" data-title="复制" onclick="hljs.copyCode(event)"></div></pre> 
<p>(2)在控制器中添加<strong>add()</strong>方法用于实现添加广告的功能，添加<strong>save()</strong>方法用于保存广告内容，添加<strong>upload()</strong>方法用于保存上传的广告图片，添加<strong>index()</strong>方法，添加<strong>delete()</strong>方法，具体代码如下：</p> 
<pre data-index="119" class="set-code-show" name="code"><code class="language-php hljs"><ol class="hljs-ln" style="width:100%"><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="1"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line"><span class="hljs-keyword">public</span> <span class="hljs-function"><span class="hljs-keyword">function</span> <span class="hljs-title">add</span>(<span class="hljs-params"><span class="hljs-variable">$id</span> = <span class="hljs-number">0</span></span>)</span>{</div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="2"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line">        <span class="hljs-variable">$data</span> = [];</div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="3"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line">        <span class="hljs-keyword">if</span>(<span class="hljs-variable">$id</span> &gt; <span class="hljs-number">0</span>){</div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="4"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line">            <span class="hljs-variable">$data</span> = <span class="hljs-title class_">Advcontent</span>::<span class="hljs-title function_ invoke__">find</span>(<span class="hljs-variable">$id</span>);</div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="5"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line">            <span class="hljs-keyword">if</span>(<span class="hljs-variable">$data</span>[<span class="hljs-string">'path'</span>]){</div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="6"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line">                <span class="hljs-variable">$data</span>[<span class="hljs-string">'path'</span>] = <span class="hljs-title function_ invoke__">explode</span>(<span class="hljs-string">"|"</span>, <span class="hljs-variable">$data</span>[<span class="hljs-string">'path'</span>]);</div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="7"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line">            }<span class="hljs-keyword">else</span>{</div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="8"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line">                <span class="hljs-variable">$data</span>[<span class="hljs-string">'path'</span>] = [];</div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="9"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line">            }</div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="10"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line">        }</div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="11"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line">        <span class="hljs-variable">$position</span> = <span class="hljs-title class_">Adv</span>::<span class="hljs-title function_ invoke__">all</span>();</div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="12"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line">        <span class="hljs-keyword">return</span> <span class="hljs-title function_ invoke__">view</span>(<span class="hljs-string">'admin.advcontent.add'</span>, [<span class="hljs-string">'data'</span> =&gt; <span class="hljs-variable">$data</span>, <span class="hljs-string">'position'</span> =&gt; <span class="hljs-variable">$position</span>]);</div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="13"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line">    }</div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="14"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line"> </div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="15"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line">    <span class="hljs-keyword">public</span> <span class="hljs-function"><span class="hljs-keyword">function</span> <span class="hljs-title">save</span>(<span class="hljs-params">Request <span class="hljs-variable">$request</span></span>)</span>{</div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="16"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line">        <span class="hljs-variable">$data</span> = <span class="hljs-variable">$request</span>-&gt;<span class="hljs-title function_ invoke__">all</span>();</div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="17"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line">        <span class="hljs-variable">$path</span> = <span class="hljs-string">''</span>;</div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="18"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line">        <span class="hljs-keyword">foreach</span>(<span class="hljs-variable">$data</span>[<span class="hljs-string">'path'</span>] <span class="hljs-keyword">as</span> <span class="hljs-variable">$v</span>){</div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="19"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line">            <span class="hljs-variable">$path</span> .= <span class="hljs-variable">$v</span> . <span class="hljs-string">"|"</span>;</div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="20"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line">        }</div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="21"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line">        <span class="hljs-variable">$data</span>[<span class="hljs-string">'path'</span>] = <span class="hljs-title function_ invoke__">substr</span>(<span class="hljs-variable">$path</span>,<span class="hljs-number">0</span>,-<span class="hljs-number">1</span>);</div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="22"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line">        <span class="hljs-keyword">if</span>(<span class="hljs-keyword">isset</span>(<span class="hljs-variable">$data</span>[<span class="hljs-string">'id'</span>])){</div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="23"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line">            <span class="hljs-variable">$id</span> = <span class="hljs-variable">$data</span>[<span class="hljs-string">'id'</span>];</div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="24"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line">            <span class="hljs-keyword">unset</span>(<span class="hljs-variable">$data</span>[<span class="hljs-string">'id'</span>]);</div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="25"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line">            <span class="hljs-keyword">unset</span>(<span class="hljs-variable">$data</span>[<span class="hljs-string">'_token'</span>]);</div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="26"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line">            <span class="hljs-variable">$res</span> = <span class="hljs-title class_">Advcontent</span>::<span class="hljs-title function_ invoke__">where</span>(<span class="hljs-string">'id'</span>,<span class="hljs-variable">$id</span>)-&gt;<span class="hljs-title function_ invoke__">update</span>(<span class="hljs-variable">$data</span>);</div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="27"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line">            <span class="hljs-variable">$type</span> = <span class="hljs-variable">$res</span> ? <span class="hljs-string">"message"</span> : <span class="hljs-string">"tip"</span>;</div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="28"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line">            <span class="hljs-variable">$message</span> = <span class="hljs-variable">$res</span> ? <span class="hljs-string">"修改成功"</span> : <span class="hljs-string">"修改失败"</span>;</div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="29"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line">            <span class="hljs-keyword">return</span> <span class="hljs-title function_ invoke__">redirect</span>(<span class="hljs-string">'advcontent'</span>)-&gt;<span class="hljs-title function_ invoke__">with</span>(<span class="hljs-variable">$type</span>, <span class="hljs-variable">$message</span>);</div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="30"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line">        }</div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="31"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line"> </div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="32"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line">        <span class="hljs-variable">$re</span> = <span class="hljs-title class_">Advcontent</span>::<span class="hljs-title function_ invoke__">create</span>(<span class="hljs-variable">$data</span>);</div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="33"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line">        <span class="hljs-keyword">if</span>(<span class="hljs-variable">$re</span>){</div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="34"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line">            <span class="hljs-keyword">return</span> <span class="hljs-title function_ invoke__">redirect</span>(<span class="hljs-string">'advcontent'</span>)-&gt;<span class="hljs-title function_ invoke__">with</span>(<span class="hljs-string">'message'</span>,<span class="hljs-string">'添加成功'</span>);</div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="35"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line">        }<span class="hljs-keyword">else</span>{</div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="36"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line">            <span class="hljs-keyword">return</span> <span class="hljs-title function_ invoke__">redirect</span>(<span class="hljs-string">'advcontent/add'</span>)-&gt;<span class="hljs-title function_ invoke__">with</span>(<span class="hljs-string">'tip'</span>,<span class="hljs-string">'添加失败'</span>);</div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="37"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line">        }</div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="38"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line">    }</div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="39"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line"> </div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="40"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line">    <span class="hljs-keyword">public</span> <span class="hljs-function"><span class="hljs-keyword">function</span> <span class="hljs-title">upload</span>(<span class="hljs-params">Request <span class="hljs-variable">$request</span></span>)</span>{</div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="41"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line">        <span class="hljs-keyword">if</span> (<span class="hljs-variable">$request</span>-&gt;<span class="hljs-title function_ invoke__">hasFile</span>(<span class="hljs-string">'image'</span>)) {</div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="42"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line">            <span class="hljs-variable">$image</span> = <span class="hljs-variable">$request</span>-&gt;<span class="hljs-title function_ invoke__">file</span>(<span class="hljs-string">'image'</span>);</div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="43"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line">            <span class="hljs-keyword">if</span> (<span class="hljs-variable">$image</span>-&gt;<span class="hljs-title function_ invoke__">isValid</span>()) {</div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="44"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line">                <span class="hljs-variable">$name</span> = <span class="hljs-title function_ invoke__">md5</span>(<span class="hljs-title function_ invoke__">microtime</span>(<span class="hljs-literal">true</span>)) . <span class="hljs-string">'.'</span> . <span class="hljs-variable">$image</span>-&gt;<span class="hljs-title function_ invoke__">extension</span>();</div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="45"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line">                <span class="hljs-variable">$image</span>-&gt;<span class="hljs-title function_ invoke__">move</span>(<span class="hljs-string">'static/upload'</span>, <span class="hljs-variable">$name</span>);</div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="46"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line">                <span class="hljs-variable">$path</span> = <span class="hljs-string">'/static/upload/'</span> . <span class="hljs-variable">$name</span>;</div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="47"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line">                <span class="hljs-variable">$returndata</span>  = <span class="hljs-keyword">array</span>(</div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="48"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line">                    <span class="hljs-string">'filename'</span> =&gt; <span class="hljs-variable">$name</span>,</div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="49"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line">                    <span class="hljs-string">'path'</span> =&gt; <span class="hljs-variable">$path</span></div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="50"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line">                );</div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="51"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line">                <span class="hljs-variable">$result</span> = [</div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="52"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line">                    <span class="hljs-string">'code'</span> =&gt; <span class="hljs-number">1</span>,</div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="53"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line">                    <span class="hljs-string">'msg'</span>  =&gt; <span class="hljs-string">'上传成功'</span>,</div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="54"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line">                    <span class="hljs-string">'time'</span> =&gt; <span class="hljs-title function_ invoke__">time</span>(),</div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="55"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line">                    <span class="hljs-string">'data'</span> =&gt; <span class="hljs-variable">$returndata</span>,</div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="56"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line">                ];</div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="57"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line"> </div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="58"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line">                <span class="hljs-keyword">return</span> <span class="hljs-title function_ invoke__">response</span>()-&gt;<span class="hljs-title function_ invoke__">json</span>(<span class="hljs-variable">$result</span>);</div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="59"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line">            }</div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="60"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line">            <span class="hljs-keyword">return</span> <span class="hljs-variable">$image</span>-&gt;<span class="hljs-title function_ invoke__">getErrorMessage</span>();</div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="61"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line">        }</div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="62"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line">        <span class="hljs-keyword">return</span> <span class="hljs-string">'文件上传失败'</span>;</div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="63"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line"> </div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="64"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line">    }</div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="65"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line"> </div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="66"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line">    <span class="hljs-keyword">public</span> <span class="hljs-function"><span class="hljs-keyword">function</span> <span class="hljs-title">index</span>(<span class="hljs-params"></span>)</span>{</div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="67"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line">        <span class="hljs-variable">$adv</span> = <span class="hljs-title class_">Advcontent</span>::<span class="hljs-title function_ invoke__">all</span>();</div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="68"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line">        <span class="hljs-keyword">foreach</span>(<span class="hljs-variable">$adv</span> <span class="hljs-keyword">as</span> <span class="hljs-variable">$v</span>){</div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="69"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line">            <span class="hljs-keyword">if</span>(<span class="hljs-variable">$v</span>[<span class="hljs-string">'path'</span>]){</div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="70"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line">                <span class="hljs-variable">$v</span>[<span class="hljs-string">'path'</span>] = <span class="hljs-title function_ invoke__">explode</span>(<span class="hljs-string">"|"</span>, <span class="hljs-variable">$v</span>[<span class="hljs-string">'path'</span>]);</div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="71"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line">            }<span class="hljs-keyword">else</span>{</div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="72"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line">                <span class="hljs-variable">$v</span>[<span class="hljs-string">'path'</span>] = [];</div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="73"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line">            }</div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="74"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line">        }</div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="75"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line">        <span class="hljs-keyword">return</span> <span class="hljs-title function_ invoke__">view</span>(<span class="hljs-string">'admin.advcontent.index'</span>, [<span class="hljs-string">'adv'</span> =&gt; <span class="hljs-variable">$adv</span>]);</div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="76"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line">    }</div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="77"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line"> </div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="78"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line">    <span class="hljs-keyword">public</span> <span class="hljs-function"><span class="hljs-keyword">function</span> <span class="hljs-title">delete</span>(<span class="hljs-params"><span class="hljs-variable">$id</span></span>)</span>{</div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="79"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line">        <span class="hljs-keyword">if</span> (!<span class="hljs-variable">$content</span> = <span class="hljs-title class_">Advcontent</span>::<span class="hljs-title function_ invoke__">find</span>(<span class="hljs-variable">$id</span>)) {</div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="80"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line">            <span class="hljs-keyword">return</span> <span class="hljs-title function_ invoke__">response</span>()-&gt;<span class="hljs-title function_ invoke__">json</span>([<span class="hljs-string">'code'</span> =&gt; <span class="hljs-number">0</span>, <span class="hljs-string">'msg'</span> =&gt; <span class="hljs-string">'删除失败，记录不存在。'</span> ]);</div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="81"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line">        }</div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="82"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line">        <span class="hljs-variable">$content</span>-&gt;<span class="hljs-title function_ invoke__">delete</span>();</div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="83"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line">        <span class="hljs-keyword">return</span> <span class="hljs-title function_ invoke__">response</span>()-&gt;<span class="hljs-title function_ invoke__">json</span>([<span class="hljs-string">'code'</span> =&gt; <span class="hljs-number">1</span>, <span class="hljs-string">'msg'</span> =&gt; <span class="hljs-string">'删除成功'</span> ]);</div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="84"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line">    }</div></div></li></ol></code><div class="hljs-button {2}" data-title="复制" onclick="hljs.copyCode(event)"></div></pre> 
<p>(3)在控制器中引入广告位的命名空间，具体代码如下：</p> 
<pre data-index="120" class="set-code-show" name="code"><code class="language-php hljs"><ol class="hljs-ln" style="width:100%"><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="1"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line"><span class="hljs-keyword">use</span> <span class="hljs-title">App</span>\<span class="hljs-title">Advcontent</span>;</div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="2"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line"><span class="hljs-keyword">use</span> <span class="hljs-title">App</span>\<span class="hljs-title">Adv</span>;</div></div></li></ol></code><div class="hljs-button {2}" data-title="复制" onclick="hljs.copyCode(event)"></div></pre> 
<p>(4)创建<strong>resources\views\admin\advcontent\add.blade.php</strong>视图文件，具体代码如下：</p> 
<pre data-index="121" class="set-code-show" name="code"><code class="language-php hljs"><ol class="hljs-ln" style="width:1660px"><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="1"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line">@<span class="hljs-keyword">extends</span>(<span class="hljs-string">'admin/layouts/admin'</span>)</div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="2"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line">@<span class="hljs-title function_ invoke__">section</span>(<span class="hljs-string">'title'</span>, <span class="hljs-string">'添加广告'</span>)</div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="3"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line">@<span class="hljs-title function_ invoke__">section</span>(<span class="hljs-string">'main'</span>)</div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="4"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line">&lt;div <span class="hljs-class"><span class="hljs-class"><span class="hljs-keyword">class</span>="<span class="hljs-title">main</span>-<span class="hljs-title">title</span>"&gt;&lt;<span class="hljs-title">h2</span>&gt;&lt;<span class="hljs-title">div</span> <span class="hljs-title">class</span>="<span class="hljs-title">main</span>-<span class="hljs-title">title</span>"&gt;&lt;<span class="hljs-title">h2</span>&gt;@<span class="hljs-title">if</span>(!<span class="hljs-title">empty</span>($<span class="hljs-title">data</span>))编辑@<span class="hljs-title">else</span>添加@<span class="hljs-title">endif</span>广告&lt;/<span class="hljs-title">h2</span>&gt;&lt;/<span class="hljs-title">div</span>&gt;</span></span></div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="5"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line"><span class="hljs-class">&lt;<span class="hljs-title">div</span> <span class="hljs-title">class</span>="<span class="hljs-title">main</span>-<span class="hljs-title">section</span>"&gt;</span></div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="6"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line"><span class="hljs-class">  &lt;<span class="hljs-title">div</span> <span class="hljs-title">style</span>="<span class="hljs-title">width</span>:543<span class="hljs-title">px</span>"&gt;</span></div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="7"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line"><span class="hljs-class">    &lt;<span class="hljs-title">form</span> <span class="hljs-title">method</span>="<span class="hljs-title">post</span>" <span class="hljs-title">action</span>="</span>{{ <span class="hljs-title function_ invoke__">url</span>(<span class="hljs-string">'/advcontent/save'</span>) }}<span class="hljs-string"><span class="hljs-string">"&gt;</span></span></div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="8"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line"><span class="hljs-string">      &lt;div class="</span>form-group row<span class="hljs-string"><span class="hljs-string">"&gt;</span></span></div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="9"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line"><span class="hljs-string">        &lt;label class="</span>col-sm-<span class="hljs-number">3</span> col-form-label<span class="hljs-string"><span class="hljs-string">"&gt;选择广告位&lt;/label&gt;</span></span></div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="10"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line"><span class="hljs-string">        &lt;div class="</span>col-sm-<span class="hljs-number">9</span><span class="hljs-string"><span class="hljs-string">"&gt;</span></span></div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="11"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line"><span class="hljs-string">          &lt;!-- 广告位列表 --&gt;</span></div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="12"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line"><span class="hljs-string">          &lt;select name="</span>advid<span class="hljs-string">" class="</span>form-control<span class="hljs-string">" style="</span>width:<span class="hljs-number">200</span>px;<span class="hljs-string"><span class="hljs-string">"&gt;</span></span></div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="13"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line"><span class="hljs-string">            @foreach (<span class="hljs-subst">$position</span> as <span class="hljs-subst">$v</span>)</span></div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="14"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line"><span class="hljs-string">            &lt;option value="</span>{{ <span class="hljs-variable">$v</span>-&gt;id }}<span class="hljs-string"><span class="hljs-string">" @if(isset(<span class="hljs-subst">$data</span>-&gt;advposid) &amp;&amp; <span class="hljs-subst">$data</span>-&gt;advposid == <span class="hljs-subst">$v</span>-&gt;id) selected @endif&gt;</span></span></div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="15"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line"><span class="hljs-string">              {{ <span class="hljs-subst">$v</span>-&gt;name }}</span></div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="16"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line"><span class="hljs-string">            &lt;/option&gt;</span></div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="17"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line"><span class="hljs-string">            @endforeach</span></div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="18"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line"><span class="hljs-string">          &lt;/select&gt;</span></div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="19"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line"><span class="hljs-string">        &lt;/div&gt;</span></div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="20"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line"><span class="hljs-string">      &lt;/div&gt;</span></div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="21"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line"><span class="hljs-string">      &lt;div class="</span>form-group row<span class="hljs-string"><span class="hljs-string">"&gt;</span></span></div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="22"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line"><span class="hljs-string">        &lt;label class="</span>col-sm-<span class="hljs-number">3</span> col-form-label<span class="hljs-string"><span class="hljs-string">"&gt;上传图片&lt;/label&gt;</span></span></div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="23"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line"><span class="hljs-string">        &lt;div class="</span>col-sm-<span class="hljs-number">9</span><span class="hljs-string"><span class="hljs-string">"&gt;</span></span></div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="24"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line"><span class="hljs-string">          &lt;input type="</span>file<span class="hljs-string">" id="</span>file1<span class="hljs-string">" name="</span>path<span class="hljs-string">" value="</span>上传图片<span class="hljs-string"><span class="hljs-string">"&gt;</span></span></div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="25"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line"><span class="hljs-string">        &lt;/div&gt;</span></div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="26"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line"><span class="hljs-string">        &lt;div class="</span>col-sm-<span class="hljs-number">9</span> offset-sm-<span class="hljs-number">3</span><span class="hljs-string"><span class="hljs-string">"&gt;</span></span></div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="27"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line"><span class="hljs-string">          &lt;div class="</span>upload-img-box<span class="hljs-string">" id="</span>uploadImg<span class="hljs-string"><span class="hljs-string">"&gt;</span></span></div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="28"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line"><span class="hljs-string">            @if(isset(<span class="hljs-subst">$data</span>-&gt;path))</span></div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="29"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line"><span class="hljs-string">            &lt;div class="</span>upload-pre-item<span class="hljs-string">" style="</span>max-height:<span class="hljs-number">100</span>%;<span class="hljs-string"><span class="hljs-string">"&gt;</span></span></div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="30"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line"><span class="hljs-string">                @foreach (<span class="hljs-subst">$data</span>-&gt;path as <span class="hljs-subst">$val</span>)</span></div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="31"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line"><span class="hljs-string">                &lt;img src="</span>/<span class="hljs-built_in">static</span>/upload/{{<span class="hljs-variable">$val</span>}}<span class="hljs-string"><span class="hljs-string">"</span></span></div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="32"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line"><span class="hljs-string">                    style="</span>width:<span class="hljs-number">100</span>px;height:<span class="hljs-number">100</span>px<span class="hljs-string"><span class="hljs-string">"/&gt;</span></span></div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="33"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line"><span class="hljs-string">                &lt;input type="</span>hidden<span class="hljs-string">" name="</span>path[]<span class="hljs-string">" value="</span>{{<span class="hljs-variable">$val</span>}}<span class="hljs-string"><span class="hljs-string">"</span></span></div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="34"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line"><span class="hljs-string">                        class="</span>icon_banner<span class="hljs-string"><span class="hljs-string">"/&gt;</span></span></div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="35"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line"><span class="hljs-string">                @endforeach</span></div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="36"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line"><span class="hljs-string">            &lt;/div&gt;</span></div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="37"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line"><span class="hljs-string">            @endif</span></div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="38"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line"><span class="hljs-string">          &lt;/div&gt;</span></div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="39"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line"><span class="hljs-string">        &lt;/div&gt;</span></div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="40"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line"><span class="hljs-string">      &lt;/div&gt;</span></div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="41"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line"><span class="hljs-string">      &lt;div class="</span>form-group row<span class="hljs-string"><span class="hljs-string">"&gt;</span></span></div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="42"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line"><span class="hljs-string">        &lt;div class="</span>col-sm-<span class="hljs-number">9</span><span class="hljs-string"><span class="hljs-string">"&gt;</span></span></div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="43"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line"><span class="hljs-string">          {{csrf_field()}}</span></div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="44"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line"><span class="hljs-string">          @if(isset(<span class="hljs-subst">$data</span>['id'])) &lt;input type="</span>hidden<span class="hljs-string">" name="</span>id<span class="hljs-string">" value="</span>{{<span class="hljs-variable">$data</span>-&gt;id}}<span class="hljs-string"><span class="hljs-string">"&gt; @endif</span></span></div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="45"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line"><span class="hljs-string">          &lt;button type="</span>submit<span class="hljs-string">" class="</span>btn btn-primary mr-<span class="hljs-number">2</span><span class="hljs-string"><span class="hljs-string">"&gt;提交表单&lt;/button&gt;</span></span></div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="46"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line"><span class="hljs-string">          &lt;a href="</span>{{ <span class="hljs-title function_ invoke__">url</span>(<span class="hljs-string">'advcontent'</span>) }}<span class="hljs-string">" class="</span>btn btn-secondary<span class="hljs-string"><span class="hljs-string">"&gt;返回列表&lt;/a&gt;</span></span></div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="47"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line"><span class="hljs-string">        &lt;/div&gt;</span></div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="48"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line"><span class="hljs-string">      &lt;/div&gt;</span></div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="49"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line"><span class="hljs-string">    &lt;/form&gt;</span></div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="50"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line"><span class="hljs-string">  &lt;/div&gt;</span></div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="51"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line"><span class="hljs-string">&lt;/div&gt;</span></div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="52"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line"><span class="hljs-string">&lt;link href="</span>{{<span class="hljs-title function_ invoke__">asset</span>(<span class="hljs-string">'admin'</span>)}}/common/uploader/uploadifive.css<span class="hljs-string">" rel="</span>stylesheet<span class="hljs-string"><span class="hljs-string">" /&gt;</span></span></div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="53"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line"><span class="hljs-string">&lt;script src="</span>{{<span class="hljs-title function_ invoke__">asset</span>(<span class="hljs-string">'admin'</span>)}}/common/uploader/jquery.uploadifive.js<span class="hljs-string"><span class="hljs-string">"&gt;&lt;/script&gt;</span></span></div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="54"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line"><span class="hljs-string">&lt;script&gt;</span></div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="55"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line"><span class="hljs-string">main.menuActive('advcontent');</span></div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="56"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line"><span class="hljs-string">$(function(){</span></div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="57"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line"><span class="hljs-string">  $('#file1').uploadifive({</span></div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="58"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line"><span class="hljs-string">    'auto'       : true,</span></div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="59"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line"><span class="hljs-string">    'fileObjName'    : 'image',</span></div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="60"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line"><span class="hljs-string">    'fileType'     : 'image',</span></div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="61"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line"><span class="hljs-string">    'buttonText'     : '上传图片',</span></div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="62"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line"><span class="hljs-string">    'formData'     : { '_token' : "</span>{{ <span class="hljs-title function_ invoke__">csrf_token</span>() }}<span class="hljs-string"><span class="hljs-string">" },</span></span></div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="63"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line"><span class="hljs-string">    'method'       : 'post',</span></div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="64"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line"><span class="hljs-string">    'queueID'      : 'uploadImg',</span></div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="65"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line"><span class="hljs-string">    'removeCompleted'  : true,</span></div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="66"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line"><span class="hljs-string">    'uploadScript'   : '{{ url('advcontent/upload')}}',</span></div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="67"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line"><span class="hljs-string">    'onUploadComplete' : uploadPicture_icon</span></div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="68"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line"><span class="hljs-string">  });</span></div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="69"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line"><span class="hljs-string">});</span></div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="70"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line"><span class="hljs-string">function uploadPicture_icon(file, data) {</span></div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="71"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line"><span class="hljs-string">  var obj = $.parseJSON(data);</span></div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="72"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line"><span class="hljs-string">  var src = '';</span></div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="73"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line"><span class="hljs-string">  if (obj.code) {</span></div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="74"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line"><span class="hljs-string">    filename = obj.data.filename;</span></div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="75"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line"><span class="hljs-string">    path = obj.data.path;</span></div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="76"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line"><span class="hljs-string">    if ($('.upload-pre-item').length &gt; 0) {</span></div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="77"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line"><span class="hljs-string">        $('.upload-pre-item').append(</span></div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="78"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line"><span class="hljs-string">            '&lt;img src="</span><span class="hljs-string">' + path + '</span><span class="hljs-string">" style="</span>width:<span class="hljs-number">100</span>px;height:<span class="hljs-number">100</span>px<span class="hljs-string">"/&gt; &lt;input type="</span>hidden<span class="hljs-string">" name="</span>path[]<span class="hljs-string">" value="</span><span class="hljs-string">'+filename+'</span><span class="hljs-string">" class="</span>icon_banner<span class="hljs-string"><span class="hljs-string">"/&gt;'</span></span></div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="79"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line"><span class="hljs-string">        );</span></div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="80"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line"><span class="hljs-string">    } else {</span></div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="81"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line"><span class="hljs-string">      $('.upload-img-box').append(</span></div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="82"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line"><span class="hljs-string">        '&lt;div class="</span>upload-pre-item<span class="hljs-string">" style="</span>max-height:<span class="hljs-number">100</span>%;<span class="hljs-string">"&gt;&lt;img src="</span><span class="hljs-string">' + path + '</span><span class="hljs-string">" style="</span>width:<span class="hljs-number">100</span>px;height:<span class="hljs-number">100</span>px<span class="hljs-string">"/&gt; &lt;input type="</span>hidden<span class="hljs-string">" name="</span>path[]<span class="hljs-string">" value="</span><span class="hljs-string">'+filename+'</span><span class="hljs-string">" class="</span>icon_banner<span class="hljs-string"><span class="hljs-string">"/&gt;&lt;/div&gt;'</span></span></div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="83"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line"><span class="hljs-string">      );</span></div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="84"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line"><span class="hljs-string">    }</span></div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="85"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line"><span class="hljs-string">  } else {</span></div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="86"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line"><span class="hljs-string">    alert(data.info);</span></div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="87"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line"><span class="hljs-string">  }</span></div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="88"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line"><span class="hljs-string">}</span></div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="89"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line"><span class="hljs-string">&lt;/script&gt;</span></div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="90"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line"><span class="hljs-string">@endsection</span></div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="91"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line"><span class="hljs-string"></span></div></div></li></ol></code><div class="hljs-button {2}" data-title="复制" onclick="hljs.copyCode(event)"></div></pre> 
<p>(5)创建<strong>index.php</strong>文件，具体代码如下：</p> 
<pre data-index="122" class="set-code-show" name="code"><code class="language-php hljs"><ol class="hljs-ln" style="width:1206px"><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="1"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line">@<span class="hljs-keyword">extends</span>(<span class="hljs-string">'admin/layouts/admin'</span>)</div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="2"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line">@<span class="hljs-title function_ invoke__">section</span>(<span class="hljs-string">'title'</span>, <span class="hljs-string">'广告内容管理'</span>)</div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="3"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line">@<span class="hljs-title function_ invoke__">section</span>(<span class="hljs-string">'main'</span>)</div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="4"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line">&lt;div <span class="hljs-class"><span class="hljs-class"><span class="hljs-keyword">class</span>="<span class="hljs-title">main</span>-<span class="hljs-title">title</span>"&gt;&lt;<span class="hljs-title">h2</span>&gt;广告内容管理&lt;/<span class="hljs-title">h2</span>&gt;&lt;/<span class="hljs-title">div</span>&gt;</span></span></div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="5"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line"><span class="hljs-class">&lt;<span class="hljs-title">div</span> <span class="hljs-title">class</span>="<span class="hljs-title">main</span>-<span class="hljs-title">section</span> <span class="hljs-title">form</span>-<span class="hljs-title">inline</span>"&gt;</span></div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="6"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line"><span class="hljs-class">  &lt;<span class="hljs-title">a</span> <span class="hljs-title">href</span>="</span>{{ <span class="hljs-title function_ invoke__">url</span>(<span class="hljs-string">'advcontent/add'</span>) }}<span class="hljs-string">" class="</span>btn btn-success<span class="hljs-string"><span class="hljs-string">"&gt;+ 新增&lt;/a&gt;</span></span></div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="7"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line"><span class="hljs-string">&lt;/div&gt;</span></div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="8"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line"><span class="hljs-string">&lt;div class="</span>main-section<span class="hljs-string"><span class="hljs-string">"&gt;</span></span></div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="9"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line"><span class="hljs-string">  &lt;table class="</span>table table-striped table-bordered table-hover<span class="hljs-string"><span class="hljs-string">"&gt;</span></span></div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="10"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line"><span class="hljs-string">    &lt;thead&gt;</span></div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="11"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line"><span class="hljs-string">    &lt;tr&gt;</span></div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="12"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line"><span class="hljs-string">      &lt;th width="</span><span class="hljs-number">75</span><span class="hljs-string">"&gt;序号&lt;/th&gt;&lt;th&gt;广告位名称&lt;/th&gt;&lt;th&gt;广告图片&lt;/th&gt;&lt;th width="</span><span class="hljs-number">100</span><span class="hljs-string"><span class="hljs-string">"&gt;操作&lt;/th&gt;</span></span></div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="13"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line"><span class="hljs-string">    &lt;/tr&gt;</span></div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="14"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line"><span class="hljs-string">    &lt;/thead&gt;</span></div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="15"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line"><span class="hljs-string">    &lt;tbody&gt;</span></div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="16"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line"><span class="hljs-string">    &lt;!-- 广告位列表 --&gt;</span></div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="17"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line"><span class="hljs-string">    @foreach(<span class="hljs-subst">$adv</span> as <span class="hljs-subst">$v</span>)</span></div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="18"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line"><span class="hljs-string">      &lt;tr class="</span>j-pid-{{ <span class="hljs-variable">$v</span>[<span class="hljs-string">'pid'</span>] }}<span class="hljs-string"><span class="hljs-string">"&gt;</span></span></div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="19"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line"><span class="hljs-string">        &lt;td&gt;&lt;input type="</span>text<span class="hljs-string">" value="</span>{{<span class="hljs-variable">$v</span>-&gt;id}}<span class="hljs-string">" class="</span>form-control j-sort<span class="hljs-string">" maxlength="</span><span class="hljs-number">5</span><span class="hljs-string">" style="</span>height:<span class="hljs-number">25</span>px;font-size:<span class="hljs-number">12</span>px;padding:<span class="hljs-number">0</span> <span class="hljs-number">5</span>px;<span class="hljs-string"><span class="hljs-string">"&gt;&lt;/td&gt;</span></span></div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="20"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line"><span class="hljs-string">        &lt;td&gt;{<span class="hljs-subst">{$v-&gt;position-&gt;name}</span>}&lt;/td&gt;</span></div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="21"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line"><span class="hljs-string">        &lt;td&gt;</span></div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="22"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line"><span class="hljs-string">          @foreach(<span class="hljs-subst">$v</span>-&gt;path as <span class="hljs-subst">$val</span>)</span></div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="23"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line"><span class="hljs-string">            &lt;img src="</span>/<span class="hljs-built_in">static</span>/upload/{{<span class="hljs-variable">$val</span>}}<span class="hljs-string">" style="</span>height:<span class="hljs-number">40</span>px;width: <span class="hljs-number">50</span>px<span class="hljs-string"><span class="hljs-string">"&gt;</span></span></div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="24"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line"><span class="hljs-string">          @endforeach</span></div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="25"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line"><span class="hljs-string">        &lt;/td&gt;</span></div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="26"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line"><span class="hljs-string">        &lt;td&gt;&lt;a href="</span>{{ <span class="hljs-title function_ invoke__">url</span>(<span class="hljs-string">'advcontent/add'</span>, [<span class="hljs-string">'id'</span> =&gt; <span class="hljs-variable">$v</span>-&gt;id]) }}<span class="hljs-string">" style="</span>margin-right:<span class="hljs-number">5</span>px;<span class="hljs-string"><span class="hljs-string">"&gt;编辑&lt;/a&gt;</span></span></div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="27"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line"><span class="hljs-string"></span></div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="28"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line"><span class="hljs-string">          &lt;a href="</span>{{ <span class="hljs-title function_ invoke__">url</span>(<span class="hljs-string">'advcontent/delete'</span>, [<span class="hljs-string">'id'</span> =&gt; <span class="hljs-variable">$v</span>-&gt;id]) }}<span class="hljs-string">" class="</span>j-del text-danger<span class="hljs-string"><span class="hljs-string">"&gt;删除&lt;/a&gt;</span></span></div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="29"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line"><span class="hljs-string">        &lt;/td&gt;</span></div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="30"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line"><span class="hljs-string">      &lt;/tr&gt;</span></div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="31"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line"><span class="hljs-string">    @endforeach</span></div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="32"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line"><span class="hljs-string">    @if(empty(<span class="hljs-subst">$adv</span>))</span></div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="33"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line"><span class="hljs-string">      &lt;tr&gt;&lt;td colspan="</span><span class="hljs-number">4</span><span class="hljs-string">" class="</span>text-center<span class="hljs-string"><span class="hljs-string">"&gt;还没有添加广告内容&lt;/td&gt;&lt;/tr&gt;</span></span></div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="34"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line"><span class="hljs-string">    @endif</span></div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="35"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line"><span class="hljs-string">    &lt;/tbody&gt;</span></div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="36"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line"><span class="hljs-string">  &lt;/table&gt;</span></div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="37"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line"><span class="hljs-string">&lt;/div&gt;</span></div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="38"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line"><span class="hljs-string">&lt;script&gt;</span></div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="39"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line"><span class="hljs-string">  main.menuActive('advcontent');</span></div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="40"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line"><span class="hljs-string">  $('.j-del').click(function() {</span></div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="41"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line"><span class="hljs-string">    if (confirm('您确定要删除此项？')) {</span></div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="42"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line"><span class="hljs-string">      var data = { _token: '{{ csrf_token() }}' };</span></div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="43"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line"><span class="hljs-string">      main.ajaxPost({url:$(this).attr('href'), data: data}, function(){</span></div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="44"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line"><span class="hljs-string">        location.reload();</span></div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="45"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line"><span class="hljs-string">      });</span></div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="46"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line"><span class="hljs-string">    }</span></div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="47"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line"><span class="hljs-string">    return false;</span></div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="48"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line"><span class="hljs-string">  });</span></div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="49"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line"><span class="hljs-string">&lt;/script&gt;</span></div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="50"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line"><span class="hljs-string">@endsection</span></div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="51"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line"><span class="hljs-string"></span></div></div></li></ol></code><div class="hljs-button {2}" data-title="复制" onclick="hljs.copyCode(event)"></div></pre> 
<p>(6)在<strong>routes\web.php</strong>中添加广告位管理的路由组，具体代码如下：</p> 
<pre data-index="123" class="set-code-show" name="code"><code class="language-php hljs"><ol class="hljs-ln" style="width:100%"><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="1"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line"><span class="hljs-comment">//广告列表</span></div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="2"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line"><span class="hljs-title class_">Route</span>::<span class="hljs-title function_ invoke__">prefix</span>(<span class="hljs-string">'advcontent'</span>)-&gt;<span class="hljs-title function_ invoke__">namespace</span>(<span class="hljs-string">'Admin'</span>)-&gt;<span class="hljs-title function_ invoke__">middleware</span>([<span class="hljs-string">'Admin'</span>])-&gt;<span class="hljs-title function_ invoke__">group</span>(function () {</div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="3"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line">    <span class="hljs-title class_">Route</span>::<span class="hljs-title function_ invoke__">get</span>(<span class="hljs-string">'add/{id?}'</span>, <span class="hljs-string">'AdvcontentController@add'</span>);</div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="4"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line">    <span class="hljs-title class_">Route</span>::<span class="hljs-title function_ invoke__">post</span>(<span class="hljs-string">'save'</span>, <span class="hljs-string">'AdvcontentController@save'</span>);</div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="5"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line">    <span class="hljs-title class_">Route</span>::<span class="hljs-title function_ invoke__">post</span>(<span class="hljs-string">'upload'</span>,<span class="hljs-string">'AdvcontentController@upload'</span>);</div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="6"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line">    <span class="hljs-title class_">Route</span>::<span class="hljs-title function_ invoke__">get</span>(<span class="hljs-string">''</span>, <span class="hljs-string">'AdvcontentController@index'</span>);</div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="7"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line">    route::<span class="hljs-title function_ invoke__">post</span>(<span class="hljs-string">'delete/{id}'</span>,<span class="hljs-string">'AdvcontentController@delete'</span>);</div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="8"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line">});</div></div></li></ol></code><div class="hljs-button {2}" data-title="复制" onclick="hljs.copyCode(event)"></div></pre> 
<p>(7)修改<strong>app\Advcontent.php</strong>，设置关联模型，获取广告位信息，具体代码如下：</p> 
<pre data-index="124" class="set-code-show" name="code"><code class="language-php hljs"><ol class="hljs-ln" style="width:100%"><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="1"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line">  <span class="hljs-keyword">public</span> <span class="hljs-function"><span class="hljs-keyword">function</span> <span class="hljs-title">position</span>(<span class="hljs-params"></span>)</span></div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="2"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line">    {</div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="3"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line">        <span class="hljs-keyword">return</span> <span class="hljs-variable language_">$this</span>-&gt;<span class="hljs-title function_ invoke__">belongsTo</span>(<span class="hljs-string">'App\Adv'</span>, <span class="hljs-string">'advid'</span>, <span class="hljs-string">'id'</span>);</div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="4"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line">    }</div></div></li></ol></code><div class="hljs-button {2}" data-title="复制" onclick="hljs.copyCode(event)"></div></pre> 
<p>（8）在Adv控制器中引入Advcontent的命名空间，具体代码如下：</p> 
<pre data-index="125" class="set-code-show" name="code"><code class="language-php hljs"><span class="hljs-keyword">use</span> <span class="hljs-title">App</span>\<span class="hljs-title">Content</span>;</code><div class="hljs-button {2}" data-title="复制" onclick="hljs.copyCode(event)"></div></pre> 
<p>(9)通过浏览器访问，可以对广告内容进行显示、编辑、删除的操作。</p> 
<p><img alt="" height="542" src="https://img-blog.csdnimg.cn/fd0aada31a21420bb3e959a76a8edbe6.png" width="1200"></p> 
<h3 id="%C2%A0%E7%BB%93%E8%AF%AD"><a name="t35"></a>&nbsp;结语</h3> 
<p>综上所述便是使用Laravel框架实现内容管理系统的后台功能。项目展示图片如下图：</p> 
<p><img alt="" height="605" src="https://img-blog.csdnimg.cn/8bfbc96d2a7a482cb694b2b849929ad6.png" width="1200"></p> 
<p>&nbsp;<img alt="" height="465" src="https://img-blog.csdnimg.cn/2a8a5a5f93b24e049021ab13bb79e8fb.png" width="1200"></p> 
<p><img alt="" height="654" src="https://img-blog.csdnimg.cn/41b5bd1b0aa2479cbdd07fb3cc46fc5f.png" width="1200"></p> 
<p><img alt="" height="943" src="https://img-blog.csdnimg.cn/d3605fd5041549058ab674111de4a014.png" width="1200"></p> 
<p><img alt="" height="942" src="https://img-blog.csdnimg.cn/e86cc6ae57c54f0081701fa9b006a43f.png" width="1200"></p> 
<p>&nbsp;<img alt="" height="523" src="https://img-blog.csdnimg.cn/7ad36aaaa26c4eee87bd32c13bb182d6.png" width="1200"></p> 
<p><img alt="" height="634" src="https://img-blog.csdnimg.cn/187539753054433a86289e824ae2f072.png" width="1200"></p> 
<h3 id="%E5%89%8D%E5%8F%B0%E9%A6%96%E9%A1%B5"><a name="t36"></a>前台首页</h3> 
<h4 id="%E4%B8%80%E3%80%81%E9%A1%B5%E9%9D%A2%E5%B8%83%E5%B1%80"><a name="t37"></a>一、页面布局</h4> 
<p>（1）在<strong>resources\views</strong>目录下创建<strong>public</strong>目录，该目录用于保存公共文件，在该目录下创建<strong>static.blade.php</strong>,用于保存静态文件，具体代码如下：</p> 
<pre data-index="126" class="set-code-show" name="code"><code class="language-php hljs"><ol class="hljs-ln" style="width:100%"><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="1"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line">&lt;meta name=<span class="hljs-string">"viewport"</span> content=<span class="hljs-string">"width=device-width, initial-scale=1.0"</span>&gt;</div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="2"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line">&lt;link rel=<span class="hljs-string">"stylesheet"</span> href=<span class="hljs-string">"{{asset('home')}}/common/twitter-bootstrap/4.4.1/css/bootstrap.min.css"</span>&gt;</div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="3"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line">&lt;link rel=<span class="hljs-string">"stylesheet"</span> href=<span class="hljs-string">"{{asset('home')}}/common/font-awesome-4.2.0/css/font-awesome.min.css"</span>&gt;</div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="4"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line">&lt;link rel=<span class="hljs-string">"stylesheet"</span> href=<span class="hljs-string">"{{asset('home')}}/css/main.css"</span>&gt;</div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="5"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line">&lt;script src=<span class="hljs-string">"{{asset('home')}}/common/jquery/1.12.4/jquery.min.js"</span>&gt;&lt;/script&gt;</div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="6"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line">&lt;script src=<span class="hljs-string">"{{asset('home')}}/common/twitter-bootstrap/4.4.1/js/bootstrap.min.js"</span>&gt;&lt;/script&gt;</div></div></li></ol></code><div class="hljs-button {2}" data-title="复制" onclick="hljs.copyCode(event)"></div></pre> 
<p>（2）创建<strong>header.blade.php</strong>文件，具体代码如下：</p> 
<pre data-index="127" class="set-code-show" name="code"><code class="language-php hljs"><ol class="hljs-ln hundred" style="width:1651px"><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="1"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line">&lt;div <span class="hljs-class"><span class="hljs-class"><span class="hljs-keyword">class</span>="<span class="hljs-title">header</span>"&gt;</span></span></div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="2"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line"><span class="hljs-class">  &lt;<span class="hljs-title">header</span>&gt;</span></div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="3"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line"><span class="hljs-class">    &lt;<span class="hljs-title">div</span> <span class="hljs-title">class</span>="<span class="hljs-title">container</span>"&gt;</span></div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="4"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line"><span class="hljs-class">      &lt;<span class="hljs-title">a</span> <span class="hljs-title">href</span>="</span>{{<span class="hljs-title function_ invoke__">url</span>(<span class="hljs-string">"/"</span>)}}<span class="hljs-string">" style="</span>color:<span class="hljs-comment">#000000"&gt;</span></div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="5"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line">        &lt;div <span class="hljs-class"><span class="hljs-class"><span class="hljs-keyword">class</span>="<span class="hljs-title">header</span>-<span class="hljs-title">logo</span>"&gt;&lt;<span class="hljs-title">span</span>&gt;内容&lt;/<span class="hljs-title">span</span>&gt;管理系统&lt;/<span class="hljs-title">div</span>&gt;</span></span></div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="6"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line"><span class="hljs-class">      &lt;/<span class="hljs-title">a</span>&gt;</span></div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="7"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line"><span class="hljs-class">      &lt;<span class="hljs-title">ul</span> <span class="hljs-title">class</span>="<span class="hljs-title">header</span>-<span class="hljs-title">right</span>"&gt;</span></div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="8"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line"><span class="hljs-class">        @<span class="hljs-title">if</span>(<span class="hljs-title">session</span>()-&gt;<span class="hljs-title">has</span>('<span class="hljs-title">users</span>.<span class="hljs-title">name</span>'))</span></div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="9"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line"><span class="hljs-class">          &lt;<span class="hljs-title">li</span>&gt;</span></div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="10"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line"><span class="hljs-class">            &lt;<span class="hljs-title">a</span> <span class="hljs-title">href</span>="#" <span class="hljs-title">class</span>="<span class="hljs-title">j</span>-<span class="hljs-title">layout</span>-<span class="hljs-title">pwd</span>"&gt;</span></div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="11"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line"><span class="hljs-class">              &lt;<span class="hljs-title">i</span> <span class="hljs-title">class</span>="<span class="hljs-title">fa</span> <span class="hljs-title">fa</span>-<span class="hljs-title">user</span> <span class="hljs-title">fa</span>-<span class="hljs-title">fw</span>"&gt;&lt;/<span class="hljs-title">i</span>&gt;</span>{{ <span class="hljs-title function_ invoke__">session</span>()-&gt;<span class="hljs-title function_ invoke__">get</span>(<span class="hljs-string">'users.name'</span>) }}</div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="12"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line">            &lt;/a&gt;</div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="13"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line">          &lt;/li&gt;</div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="14"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line">          &lt;li&gt;&lt;a href=<span class="hljs-string">"{{ url('logout') }}"</span>&gt;&lt;i <span class="hljs-class"><span class="hljs-class"><span class="hljs-keyword">class</span>="<span class="hljs-title">fa</span> <span class="hljs-title">fa</span>-<span class="hljs-title">power</span>-<span class="hljs-title">off</span> <span class="hljs-title">fa</span>-<span class="hljs-title">fw</span>"&gt;&lt;/<span class="hljs-title">i</span>&gt;退出&lt;/<span class="hljs-title">a</span>&gt;&lt;/<span class="hljs-title">li</span>&gt;</span></span></div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="15"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line"><span class="hljs-class">        @<span class="hljs-title">else</span></span></div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="16"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line"><span class="hljs-class">          &lt;<span class="hljs-title">li</span>&gt;&lt;<span class="hljs-title">a</span> <span class="hljs-title">href</span>="#" <span class="hljs-title">data</span>-<span class="hljs-title">toggle</span>="<span class="hljs-title">modal</span>" <span class="hljs-title">data</span>-<span class="hljs-title">target</span>="#<span class="hljs-title">loginModal</span>"&gt;登录&lt;/<span class="hljs-title">a</span>&gt;&lt;/<span class="hljs-title">li</span>&gt;</span></div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="17"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line"><span class="hljs-class">          &lt;<span class="hljs-title">li</span>&gt;&lt;<span class="hljs-title">a</span> <span class="hljs-title">href</span>="#" <span class="hljs-title">data</span>-<span class="hljs-title">toggle</span>="<span class="hljs-title">modal</span>" <span class="hljs-title">data</span>-<span class="hljs-title">target</span>="#<span class="hljs-title">registerModal</span>"&gt;注册&lt;/<span class="hljs-title">a</span>&gt;&lt;/<span class="hljs-title">li</span>&gt;</span></div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="18"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line"><span class="hljs-class">        @<span class="hljs-title">endif</span></span></div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="19"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line"><span class="hljs-class">      &lt;/<span class="hljs-title">ul</span>&gt;</span></div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="20"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line"><span class="hljs-class">    &lt;/<span class="hljs-title">div</span>&gt;</span></div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="21"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line"><span class="hljs-class">  &lt;/<span class="hljs-title">header</span>&gt;</span></div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="22"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line"><span class="hljs-class">  &lt;!-- 栏目列表 --&gt;</span></div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="23"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line"><span class="hljs-class">  &lt;<span class="hljs-title">nav</span> <span class="hljs-title">class</span>="<span class="hljs-title">navbar</span> <span class="hljs-title">navbar</span>-<span class="hljs-title">expand</span>-<span class="hljs-title">md</span> <span class="hljs-title">navbar</span>-<span class="hljs-title">dark</span>"&gt;</span></div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="24"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line"><span class="hljs-class">    &lt;<span class="hljs-title">div</span> <span class="hljs-title">class</span>="<span class="hljs-title">container</span>"&gt;</span></div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="25"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line"><span class="hljs-class">      &lt;<span class="hljs-title">div</span>&gt;&lt;/<span class="hljs-title">div</span>&gt;</span></div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="26"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line"><span class="hljs-class">      &lt;<span class="hljs-title">button</span> <span class="hljs-title">class</span>="<span class="hljs-title">navbar</span>-<span class="hljs-title">toggler</span>" <span class="hljs-title">type</span>="<span class="hljs-title">button</span>" <span class="hljs-title">data</span>-<span class="hljs-title">toggle</span>="<span class="hljs-title">collapse</span>" <span class="hljs-title">data</span>-<span class="hljs-title">target</span>="#<span class="hljs-title">navbarSupportedContent</span>" <span class="hljs-title">aria</span>-<span class="hljs-title">expanded</span>="<span class="hljs-title">false</span>" <span class="hljs-title">aria</span>-<span class="hljs-title">controls</span>="<span class="hljs-title">navbarSupportedContent</span>" <span class="hljs-title">aria</span>-<span class="hljs-title">label</span>="<span class="hljs-title">Toggle</span> <span class="hljs-title">navigation</span>"&gt;</span></div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="27"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line"><span class="hljs-class">        &lt;<span class="hljs-title">span</span> <span class="hljs-title">class</span>="<span class="hljs-title">navbar</span>-<span class="hljs-title">toggler</span>-<span class="hljs-title">icon</span>"&gt;&lt;/<span class="hljs-title">span</span>&gt;</span></div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="28"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line"><span class="hljs-class">      &lt;/<span class="hljs-title">button</span>&gt;</span></div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="29"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line"><span class="hljs-class">      &lt;<span class="hljs-title">div</span> <span class="hljs-title">class</span>="<span class="hljs-title">collapse</span> <span class="hljs-title">navbar</span>-<span class="hljs-title">collapse</span>" <span class="hljs-title">id</span>="<span class="hljs-title">navbarSupportedContent</span>"&gt;</span></div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="30"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line"><span class="hljs-class">        &lt;<span class="hljs-title">ul</span> <span class="hljs-title">class</span>="<span class="hljs-title">navbar</span>-<span class="hljs-title">nav</span> <span class="hljs-title">mr</span>-<span class="hljs-title">auto</span>"&gt;</span></div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="31"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line"><span class="hljs-class">          &lt;<span class="hljs-title">li</span> <span class="hljs-title">class</span>="<span class="hljs-title">nav</span>-<span class="hljs-title">item</span>"&gt;</span></div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="32"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line"><span class="hljs-class">            &lt;<span class="hljs-title">a</span> <span class="hljs-title">class</span>="<span class="hljs-title">nav</span>-<span class="hljs-title">link</span>" <span class="hljs-title">href</span>="/"&gt;首页&lt;/<span class="hljs-title">a</span>&gt;</span></div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="33"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line"><span class="hljs-class">          &lt;/<span class="hljs-title">li</span>&gt;</span></div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="34"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line"><span class="hljs-class">          @<span class="hljs-title">foreach</span>($<span class="hljs-title">category</span> <span class="hljs-title">as</span> $<span class="hljs-title">v</span>)</span></div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="35"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line"><span class="hljs-class">            @<span class="hljs-title">if</span>(<span class="hljs-title">isset</span>($<span class="hljs-title">v</span>['<span class="hljs-title">sub</span>']))</span></div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="36"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line"><span class="hljs-class">              &lt;<span class="hljs-title">li</span> <span class="hljs-title">class</span>="<span class="hljs-title">nav</span>-<span class="hljs-title">item</span> <span class="hljs-title">dropdown</span>"&gt;</span></div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="37"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line"><span class="hljs-class">                &lt;<span class="hljs-title">a</span> <span class="hljs-title">class</span>="<span class="hljs-title">nav</span>-<span class="hljs-title">link</span> <span class="hljs-title">dropdown</span>-<span class="hljs-title">toggle</span>" <span class="hljs-title">href</span>="#" <span class="hljs-title">id</span>="<span class="hljs-title">navbarDropdown</span>" <span class="hljs-title">role</span>="<span class="hljs-title">button</span>" <span class="hljs-title">data</span>-<span class="hljs-title">toggle</span>="<span class="hljs-title">dropdown</span>" <span class="hljs-title">aria</span>-<span class="hljs-title">haspopup</span>="<span class="hljs-title">true</span>" <span class="hljs-title">aria</span>-<span class="hljs-title">expanded</span>="<span class="hljs-title">false</span>"&gt;</span></div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="38"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line"><span class="hljs-class">                  </span>{{<span class="hljs-variable">$v</span>[<span class="hljs-string">'name'</span>]}}</div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="39"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line">                &lt;/a&gt;</div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="40"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line">                &lt;div <span class="hljs-class"><span class="hljs-class"><span class="hljs-keyword">class</span>="<span class="hljs-title">dropdown</span>-<span class="hljs-title">menu</span>" <span class="hljs-title">aria</span>-<span class="hljs-title">labelledby</span>="<span class="hljs-title">navbarDropdown</span>"&gt;</span></span></div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="41"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line"><span class="hljs-class">                  @<span class="hljs-title">foreach</span>($<span class="hljs-title">v</span>['<span class="hljs-title">sub</span>'] <span class="hljs-title">as</span> $<span class="hljs-title">val</span>)</span></div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="42"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line"><span class="hljs-class">                    &lt;<span class="hljs-title">a</span> <span class="hljs-title">class</span>="<span class="hljs-title">dropdown</span>-<span class="hljs-title">item</span>" <span class="hljs-title">href</span>="</span>{{<span class="hljs-title function_ invoke__">url</span>(<span class="hljs-string">'lists'</span>, [<span class="hljs-string">'id'</span> =&gt; <span class="hljs-variable">$val</span>[<span class="hljs-string">'id'</span>]] )}}<span class="hljs-string"><span class="hljs-string">"&gt;{<span class="hljs-subst">{$val['name']}</span>}&lt;/a&gt;</span></span></div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="43"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line"><span class="hljs-string">                  @endforeach</span></div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="44"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line"><span class="hljs-string">                &lt;/div&gt;</span></div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="45"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line"><span class="hljs-string">              &lt;/li&gt;</span></div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="46"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line"><span class="hljs-string">            @else</span></div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="47"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line"><span class="hljs-string">              &lt;li class="</span>nav-item<span class="hljs-string"><span class="hljs-string">"&gt;</span></span></div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="48"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line"><span class="hljs-string">                &lt;a class="</span>nav-link<span class="hljs-string">" href="</span>{{<span class="hljs-title function_ invoke__">url</span>(<span class="hljs-string">'lists'</span>, [<span class="hljs-string">'id'</span> =&gt; <span class="hljs-variable">$v</span>[<span class="hljs-string">'id'</span>]] )}}<span class="hljs-string"><span class="hljs-string">"&gt;{<span class="hljs-subst">{$v['name']}</span>}&lt;/a&gt;</span></span></div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="49"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line"><span class="hljs-string">              &lt;/li&gt;</span></div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="50"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line"><span class="hljs-string">            @endif</span></div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="51"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line"><span class="hljs-string">          @endforeach</span></div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="52"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line"><span class="hljs-string">        &lt;/ul&gt;</span></div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="53"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line"><span class="hljs-string">      &lt;/div&gt;</span></div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="54"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line"><span class="hljs-string">    &lt;/div&gt;</span></div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="55"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line"><span class="hljs-string">  &lt;/nav&gt;</span></div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="56"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line"><span class="hljs-string">&lt;/div&gt;</span></div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="57"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line"><span class="hljs-string">&lt;!-- 登录表单 ---&gt;</span></div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="58"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line"><span class="hljs-string">&lt;div class="</span>modal fade<span class="hljs-string">" id="</span>loginModal<span class="hljs-string">" tabindex="</span>-<span class="hljs-number">1</span><span class="hljs-string">" role="</span>dialog<span class="hljs-string">" aria-labelledby="</span>exampleModalLabel<span class="hljs-string">" aria-hidden="</span><span class="hljs-literal">true</span><span class="hljs-string"><span class="hljs-string">"&gt;</span></span></div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="59"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line"><span class="hljs-string">  &lt;div class="</span>modal-dialog<span class="hljs-string"><span class="hljs-string">"&gt;</span></span></div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="60"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line"><span class="hljs-string">    &lt;div class="</span>modal-content<span class="hljs-string"><span class="hljs-string">"&gt;</span></span></div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="61"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line"><span class="hljs-string">      &lt;div class="</span>modal-header<span class="hljs-string"><span class="hljs-string">"&gt;</span></span></div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="62"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line"><span class="hljs-string">        &lt;h5 class="</span>modal-title<span class="hljs-string"><span class="hljs-string">"&gt;登录&lt;/h5&gt;</span></span></div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="63"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line"><span class="hljs-string">        &lt;button type="</span>button<span class="hljs-string">" class="</span>close<span class="hljs-string">" data-dismiss="</span>modal<span class="hljs-string">" aria-label="</span>Close<span class="hljs-string"><span class="hljs-string">"&gt;</span></span></div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="64"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line"><span class="hljs-string">          &lt;span aria-hidden="</span><span class="hljs-literal">true</span><span class="hljs-string"><span class="hljs-string">"&gt;&amp;times;&lt;/span&gt;</span></span></div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="65"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line"><span class="hljs-string">        &lt;/button&gt;</span></div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="66"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line"><span class="hljs-string">      &lt;/div&gt;</span></div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="67"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line"><span class="hljs-string">      &lt;div class="</span>modal-body<span class="hljs-string"><span class="hljs-string">"&gt;</span></span></div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="68"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line"><span class="hljs-string">        &lt;div class="</span>form-group<span class="hljs-string"><span class="hljs-string">"&gt;</span></span></div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="69"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line"><span class="hljs-string">          &lt;label for="</span>username<span class="hljs-string"><span class="hljs-string">"&gt;用户名&lt;/label&gt;</span></span></div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="70"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line"><span class="hljs-string">          &lt;input type="</span>text<span class="hljs-string">" name="</span>name<span class="hljs-string">" class="</span>form-control<span class="hljs-string">" id="</span>username<span class="hljs-string"><span class="hljs-string">"&gt;</span></span></div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="71"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line"><span class="hljs-string">        &lt;/div&gt;</span></div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="72"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line"><span class="hljs-string">        &lt;div class="</span>form-group<span class="hljs-string"><span class="hljs-string">"&gt;</span></span></div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="73"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line"><span class="hljs-string">          &lt;label for="</span>password<span class="hljs-string"><span class="hljs-string">"&gt;密码&lt;/label&gt;</span></span></div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="74"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line"><span class="hljs-string">          &lt;input type="</span>password<span class="hljs-string">" name="</span>password<span class="hljs-string">" class="</span>form-control<span class="hljs-string">" id="</span>password<span class="hljs-string"><span class="hljs-string">"&gt;</span></span></div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="75"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line"><span class="hljs-string">        &lt;/div&gt;</span></div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="76"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line"><span class="hljs-string">      &lt;/div&gt;</span></div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="77"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line"><span class="hljs-string">      &lt;div class="</span>modal-footer<span class="hljs-string"><span class="hljs-string">"&gt;</span></span></div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="78"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line"><span class="hljs-string">        &lt;button type="</span>button<span class="hljs-string">" class="</span>btn btn-secondary<span class="hljs-string">" data-dismiss="</span>modal<span class="hljs-string"><span class="hljs-string">"&gt;关闭&lt;/button&gt;</span></span></div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="79"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line"><span class="hljs-string">        &lt;button type="</span>submit<span class="hljs-string">" class="</span>btn btn-primary<span class="hljs-string">" id="</span>login<span class="hljs-string"><span class="hljs-string">"&gt;登录</span></span></div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="80"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line"><span class="hljs-string">        &lt;/button&gt;</span></div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="81"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line"><span class="hljs-string">      &lt;/div&gt;</span></div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="82"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line"><span class="hljs-string">    &lt;/div&gt;</span></div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="83"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line"><span class="hljs-string">  &lt;/div&gt;</span></div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="84"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line"><span class="hljs-string">&lt;/div&gt;</span></div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="85"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line"><span class="hljs-string">&lt;!-- 注册表单 ---&gt;</span></div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="86"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line"><span class="hljs-string">&lt;div class="</span>modal fade<span class="hljs-string">" id="</span>registerModal<span class="hljs-string">" tabindex="</span>-<span class="hljs-number">1</span><span class="hljs-string">" role="</span>dialog<span class="hljs-string">" aria-labelledby="</span>exampleModalLabel<span class="hljs-string">" aria-hidden="</span><span class="hljs-literal">true</span><span class="hljs-string"><span class="hljs-string">"&gt;</span></span></div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="87"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line"><span class="hljs-string">  &lt;div class="</span>modal-dialog<span class="hljs-string"><span class="hljs-string">"&gt;</span></span></div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="88"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line"><span class="hljs-string">    &lt;div class="</span>modal-content<span class="hljs-string"><span class="hljs-string">"&gt;</span></span></div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="89"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line"><span class="hljs-string">      &lt;div class="</span>modal-header<span class="hljs-string"><span class="hljs-string">"&gt;</span></span></div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="90"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line"><span class="hljs-string">        &lt;h5 class="</span>modal-title<span class="hljs-string"><span class="hljs-string">"&gt;注册&lt;/h5&gt;</span></span></div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="91"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line"><span class="hljs-string">        &lt;button type="</span>button<span class="hljs-string">" class="</span>close<span class="hljs-string">" data-dismiss="</span>modal<span class="hljs-string">" aria-label="</span>Close<span class="hljs-string"><span class="hljs-string">"&gt;</span></span></div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="92"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line"><span class="hljs-string">          &lt;span aria-hidden="</span><span class="hljs-literal">true</span><span class="hljs-string"><span class="hljs-string">"&gt;&amp;times;&lt;/span&gt;</span></span></div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="93"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line"><span class="hljs-string">        &lt;/button&gt;</span></div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="94"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line"><span class="hljs-string">      &lt;/div&gt;</span></div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="95"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line"><span class="hljs-string">      &lt;div class="</span>modal-body<span class="hljs-string"><span class="hljs-string">"&gt;</span></span></div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="96"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line"><span class="hljs-string">        &lt;div class="</span>form-group<span class="hljs-string"><span class="hljs-string">"&gt;</span></span></div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="97"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line"><span class="hljs-string">          &lt;label for="</span>username1<span class="hljs-string"><span class="hljs-string">"&gt;用户名&lt;/label&gt;</span></span></div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="98"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line"><span class="hljs-string">          &lt;input type="</span>text<span class="hljs-string">" name="</span>name<span class="hljs-string">" class="</span>form-control<span class="hljs-string">" id="</span>username1<span class="hljs-string"><span class="hljs-string">"&gt;</span></span></div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="99"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line"><span class="hljs-string">        &lt;/div&gt;</span></div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="100"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line"><span class="hljs-string">        &lt;div class="</span>form-group<span class="hljs-string"><span class="hljs-string">"&gt;</span></span></div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="101"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line"><span class="hljs-string">          &lt;label for="</span>email<span class="hljs-string"><span class="hljs-string">"&gt;邮箱&lt;/label&gt;</span></span></div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="102"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line"><span class="hljs-string">          &lt;input type="</span>email<span class="hljs-string">" name="</span>email<span class="hljs-string">" class="</span>form-control<span class="hljs-string">" id="</span>email<span class="hljs-string"><span class="hljs-string">"&gt;</span></span></div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="103"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line"><span class="hljs-string">        &lt;/div&gt;</span></div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="104"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line"><span class="hljs-string">        &lt;div class="</span>form-group<span class="hljs-string"><span class="hljs-string">"&gt;</span></span></div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="105"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line"><span class="hljs-string">          &lt;label for="</span>password1<span class="hljs-string"><span class="hljs-string">"&gt;密码&lt;/label&gt;</span></span></div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="106"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line"><span class="hljs-string">          &lt;input type="</span>password<span class="hljs-string">" name="</span>password<span class="hljs-string">" class="</span>form-control<span class="hljs-string">" id="</span>password1<span class="hljs-string"><span class="hljs-string">"&gt;</span></span></div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="107"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line"><span class="hljs-string">        &lt;/div&gt;</span></div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="108"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line"><span class="hljs-string">        &lt;div class="</span>form-group<span class="hljs-string"><span class="hljs-string">"&gt;</span></span></div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="109"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line"><span class="hljs-string">          &lt;label for="</span>confirm<span class="hljs-string"><span class="hljs-string">"&gt;确认密码&lt;/label&gt;</span></span></div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="110"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line"><span class="hljs-string">          &lt;input type="</span>password<span class="hljs-string">" class="</span>form-control<span class="hljs-string">" id="</span>confirm<span class="hljs-string"><span class="hljs-string">"&gt;</span></span></div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="111"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line"><span class="hljs-string">        &lt;/div&gt;</span></div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="112"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line"><span class="hljs-string">      &lt;/div&gt;</span></div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="113"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line"><span class="hljs-string">      &lt;div class="</span>modal-footer<span class="hljs-string"><span class="hljs-string">"&gt;</span></span></div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="114"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line"><span class="hljs-string">        {{csrf_field()}}</span></div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="115"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line"><span class="hljs-string">        &lt;button type="</span>button<span class="hljs-string">" class="</span>btn btn-secondary<span class="hljs-string">" data-dismiss="</span>modal<span class="hljs-string"><span class="hljs-string">"&gt;关闭&lt;/button&gt;</span></span></div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="116"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line"><span class="hljs-string">        &lt;button type="</span>submit<span class="hljs-string">" class="</span>btn btn-primary<span class="hljs-string">" id="</span>register<span class="hljs-string"><span class="hljs-string">"&gt;立即注册&lt;/button&gt;</span></span></div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="117"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line"><span class="hljs-string">      &lt;/div&gt;</span></div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="118"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line"><span class="hljs-string">    &lt;/div&gt;</span></div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="119"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line"><span class="hljs-string">  &lt;/div&gt;</span></div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="120"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line"><span class="hljs-string">&lt;/div&gt;</span></div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="121"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line"><span class="hljs-string">&lt;script&gt;</span></div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="122"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line"><span class="hljs-string">  $("</span><span class="hljs-comment">#login").bind("click",function(){</span></div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="123"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line">    <span class="hljs-keyword">var</span> data = {</div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="124"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line">      <span class="hljs-string">'name'</span>   : $(<span class="hljs-string">"#username"</span>).<span class="hljs-title function_ invoke__">val</span>(),</div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="125"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line">      <span class="hljs-string">'password'</span> : $(<span class="hljs-string">"#password"</span>).<span class="hljs-title function_ invoke__">val</span>(),</div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="126"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line">      <span class="hljs-string">'_token'</span>   : <span class="hljs-string">"{{ csrf_token() }}"</span></div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="127"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line">    };</div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="128"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line">    $.<span class="hljs-title function_ invoke__">post</span>(<span class="hljs-string">"{{ url('login') }}"</span>, data, function(result){</div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="129"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line">      <span class="hljs-keyword">if</span> (result.status == <span class="hljs-number">1</span>) {</div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="130"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line">        <span class="hljs-title function_ invoke__">alert</span>(result.msg);</div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="131"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line">        window.location.<span class="hljs-title function_ invoke__">reload</span>();</div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="132"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line">      } <span class="hljs-keyword">else</span> {</div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="133"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line">        <span class="hljs-title function_ invoke__">alert</span>(result.msg);</div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="134"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line">        <span class="hljs-keyword">return</span>;</div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="135"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line">      }</div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="136"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line">    });</div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="137"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line">  });</div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="138"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line">  $(<span class="hljs-string">"#register"</span>).<span class="hljs-title function_ invoke__">bind</span>(<span class="hljs-string">"click"</span>,function(){</div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="139"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line">    <span class="hljs-keyword">var</span> data = {</div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="140"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line">      <span class="hljs-string">'name'</span>           : $(<span class="hljs-string">"#username1"</span>).<span class="hljs-title function_ invoke__">val</span>(),</div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="141"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line">      <span class="hljs-string">'email'</span>          : $(<span class="hljs-string">"#email"</span>).<span class="hljs-title function_ invoke__">val</span>(),</div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="142"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line">      <span class="hljs-string">'password'</span>         : $(<span class="hljs-string">"#password1"</span>).<span class="hljs-title function_ invoke__">val</span>(),</div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="143"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line">      <span class="hljs-string">' password_confirmation'</span> : $(<span class="hljs-string">"#confirm"</span>).<span class="hljs-title function_ invoke__">val</span>(),</div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="144"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line">      <span class="hljs-string">'_token'</span>         : <span class="hljs-string">"{{ csrf_token() }}"</span></div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="145"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line">    };</div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="146"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line">    $.<span class="hljs-title function_ invoke__">post</span>(<span class="hljs-string">"{{ url('register') }}"</span>, data, function(result){</div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="147"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line">      <span class="hljs-keyword">if</span> (result.status == <span class="hljs-number">1</span>) {</div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="148"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line">        <span class="hljs-title function_ invoke__">alert</span>(result.msg);</div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="149"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line">        $(<span class="hljs-string">'#registerModal'</span>).<span class="hljs-title function_ invoke__">modal</span>(<span class="hljs-string">'hide'</span>);</div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="150"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line">        location.<span class="hljs-title function_ invoke__">reload</span>();</div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="151"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line">      } <span class="hljs-keyword">else</span> {</div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="152"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line">        <span class="hljs-title function_ invoke__">alert</span>(result.msg);</div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="153"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line">        <span class="hljs-keyword">return</span>;</div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="154"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line">      }</div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="155"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line">    });</div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="156"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line">  });</div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="157"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line">&lt;/script&gt;</div></div></li></ol></code><div class="hljs-button {2}" data-title="复制" onclick="hljs.copyCode(event)"></div></pre> 
<p>（3）创建<strong>resources\views\common\footer.blade.php</strong>文件，该文件用于保存页面底部的内容，具体代码如下：</p> 
<pre data-index="128" class="set-code-show" name="code"><code class="language-php hljs"><ol class="hljs-ln" style="width:100%"><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="1"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line">&lt;div <span class="hljs-class"><span class="hljs-class"><span class="hljs-keyword">class</span>="<span class="hljs-title">footer</span>"&gt;</span></span></div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="2"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line"><span class="hljs-class">  &lt;<span class="hljs-title">div</span> <span class="hljs-title">class</span>="<span class="hljs-title">container</span>"&gt;内容管理系统&lt;/<span class="hljs-title">div</span>&gt;</span></div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="3"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line"><span class="hljs-class">&lt;/<span class="hljs-title">div</span>&gt;</span></div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="4"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line"><span class="hljs-class"></span></div></div></li></ol></code><div class="hljs-button {2}" data-title="复制" onclick="hljs.copyCode(event)"></div></pre> 
<h4 id="%E4%BA%8C%E3%80%81%E9%A6%96%E9%A1%B5%E3%80%81%E6%A0%8F%E7%9B%AE%E5%AF%BC%E8%88%AA%E3%80%81%E8%BD%AE%E6%92%AD%E5%9B%BE%E3%80%81%E5%B9%BF%E5%91%8A%E4%BD%8D%E3%80%81%E6%A0%8F%E7%9B%AE%E5%86%85%E5%AE%B9%E5%B1%95%E7%A4%BA"><a name="t38"></a>二、首页、栏目导航、轮播图、广告位、栏目内容展示</h4> 
<p>(1)创建首页视图，在<strong>resources\views</strong>目录下创建<strong>index.blade.php</strong>，具体代码如下：</p> 
<pre data-index="129" class="set-code-show" name="code"><code class="language-php hljs"><ol class="hljs-ln" style="width:100%"><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="1"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line">&lt;!DOCTYPE html&gt;</div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="2"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line">&lt;html&gt;</div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="3"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line">&lt;head&gt;</div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="4"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line">  @<span class="hljs-keyword">include</span>(<span class="hljs-string">'public/static'</span>)</div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="5"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line">  &lt;title&gt;首页&lt;/title&gt;</div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="6"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line">&lt;/head&gt;</div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="7"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line">&lt;body&gt;</div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="8"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line">@<span class="hljs-keyword">include</span>(<span class="hljs-string">'public/header'</span>)</div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="9"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line">&lt;div <span class="hljs-class"><span class="hljs-class"><span class="hljs-keyword">class</span>="<span class="hljs-title">main</span>"&gt;</span></span></div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="10"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line"><span class="hljs-class">  &lt;<span class="hljs-title">div</span> <span class="hljs-title">class</span>="<span class="hljs-title">container</span>"&gt;</span></div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="11"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line"><span class="hljs-class">    &lt;<span class="hljs-title">div</span> <span class="hljs-title">class</span>="<span class="hljs-title">row</span> <span class="hljs-title">mt</span>-4"&gt;</span></div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="12"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line"><span class="hljs-class">      &lt;!-- 轮播图 --&gt;</span></div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="13"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line"><span class="hljs-class">      &lt;<span class="hljs-title">div</span> <span class="hljs-title">class</span>="<span class="hljs-title">col</span>-<span class="hljs-title">md</span>-6 <span class="hljs-title">main</span>-<span class="hljs-title">carousel</span>"&gt;</span></div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="14"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line"><span class="hljs-class">        &lt;<span class="hljs-title">div</span> <span class="hljs-title">id</span>="<span class="hljs-title">carouselExampleCaptions</span>" <span class="hljs-title">class</span>="<span class="hljs-title">carousel</span> <span class="hljs-title">slide</span>" <span class="hljs-title">data</span>-<span class="hljs-title">ride</span>="<span class="hljs-title">carousel</span>"&gt;</span></div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="15"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line"><span class="hljs-class">          &lt;<span class="hljs-title">div</span> <span class="hljs-title">class</span>="<span class="hljs-title">carousel</span>-<span class="hljs-title">inner</span>"&gt;</span></div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="16"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line"><span class="hljs-class">            @<span class="hljs-title">foreach</span>($<span class="hljs-title">recommend</span> <span class="hljs-title">as</span> $<span class="hljs-title">k</span>=&gt;$<span class="hljs-title">con</span>)</span></div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="17"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line"><span class="hljs-class">              &lt;<span class="hljs-title">div</span> <span class="hljs-title">class</span>="<span class="hljs-title">carousel</span>-<span class="hljs-title">item</span> @<span class="hljs-title">if</span>($<span class="hljs-title">k</span>==0) <span class="hljs-title">active</span> @<span class="hljs-title">endif</span>"&gt;</span></div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="18"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line"><span class="hljs-class">                &lt;<span class="hljs-title">img</span> <span class="hljs-title">src</span>="/<span class="hljs-title">static</span>/<span class="hljs-title">upload</span>/</span>{{<span class="hljs-variable">$con</span>-&gt;image}}<span class="hljs-string">" class="</span>d-block w-<span class="hljs-number">100</span><span class="hljs-string"><span class="hljs-string">"&gt;</span></span></div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="19"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line"><span class="hljs-string">                &lt;a href="</span>{{<span class="hljs-title function_ invoke__">url</span>(<span class="hljs-string">'detail'</span>, [<span class="hljs-string">'id'</span>=&gt; <span class="hljs-variable">$con</span>-&gt;id])}}<span class="hljs-string"><span class="hljs-string">"&gt;</span></span></div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="20"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line"><span class="hljs-string">                  &lt;div class="</span>carousel-caption d-none d-md-block<span class="hljs-string"><span class="hljs-string">"&gt;</span></span></div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="21"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line"><span class="hljs-string">                    &lt;h5&gt;{<span class="hljs-subst">{$con-&gt;title}</span>}&lt;/h5&gt;</span></div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="22"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line"><span class="hljs-string">                    &lt;p&gt;&lt;/p&gt;</span></div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="23"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line"><span class="hljs-string">                  &lt;/div&gt;</span></div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="24"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line"><span class="hljs-string">                &lt;/a&gt;</span></div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="25"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line"><span class="hljs-string">              &lt;/div&gt;</span></div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="26"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line"><span class="hljs-string">            @endforeach</span></div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="27"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line"><span class="hljs-string">          &lt;/div&gt;</span></div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="28"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line"><span class="hljs-string">          &lt;a class="</span>carousel-control-prev<span class="hljs-string">" href="</span><span class="hljs-comment">#carouselExampleCaptions" role="button" data-slide="prev"&gt;</span></div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="29"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line">            &lt;span <span class="hljs-class"><span class="hljs-class"><span class="hljs-keyword">class</span>="<span class="hljs-title">carousel</span>-<span class="hljs-title">control</span>-<span class="hljs-title">prev</span>-<span class="hljs-title">icon</span>" <span class="hljs-title">aria</span>-<span class="hljs-title">hidden</span>="<span class="hljs-title">true</span>"&gt;&lt;/<span class="hljs-title">span</span>&gt;</span></span></div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="30"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line"><span class="hljs-class">            &lt;<span class="hljs-title">span</span> <span class="hljs-title">class</span>="<span class="hljs-title">sr</span>-<span class="hljs-title">only</span>"&gt;<span class="hljs-title">Previous</span>&lt;/<span class="hljs-title">span</span>&gt;</span></div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="31"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line"><span class="hljs-class">          &lt;/<span class="hljs-title">a</span>&gt;</span></div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="32"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line"><span class="hljs-class">          &lt;<span class="hljs-title">a</span> <span class="hljs-title">class</span>="<span class="hljs-title">carousel</span>-<span class="hljs-title">control</span>-<span class="hljs-title">next</span>" <span class="hljs-title">href</span>="#<span class="hljs-title">carouselExampleCaptions</span>" <span class="hljs-title">role</span>="<span class="hljs-title">button</span>" <span class="hljs-title">data</span>-<span class="hljs-title">slide</span>="<span class="hljs-title">next</span>"&gt;</span></div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="33"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line"><span class="hljs-class">            &lt;<span class="hljs-title">span</span> <span class="hljs-title">class</span>="<span class="hljs-title">carousel</span>-<span class="hljs-title">control</span>-<span class="hljs-title">next</span>-<span class="hljs-title">icon</span>" <span class="hljs-title">aria</span>-<span class="hljs-title">hidden</span>="<span class="hljs-title">true</span>"&gt;&lt;/<span class="hljs-title">span</span>&gt;</span></div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="34"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line"><span class="hljs-class">            &lt;<span class="hljs-title">span</span> <span class="hljs-title">class</span>="<span class="hljs-title">sr</span>-<span class="hljs-title">only</span>"&gt;<span class="hljs-title">Next</span>&lt;/<span class="hljs-title">span</span>&gt;</span></div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="35"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line"><span class="hljs-class">          &lt;/<span class="hljs-title">a</span>&gt;</span></div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="36"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line"><span class="hljs-class">        &lt;/<span class="hljs-title">div</span>&gt;</span></div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="37"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line"><span class="hljs-class">      &lt;/<span class="hljs-title">div</span>&gt;</span></div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="38"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line"><span class="hljs-class">      &lt;!-- 广告位 --&gt;</span></div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="39"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line"><span class="hljs-class">      &lt;<span class="hljs-title">div</span> <span class="hljs-title">class</span>="<span class="hljs-title">col</span>-<span class="hljs-title">md</span>-6"&gt;</span></div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="40"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line"><span class="hljs-class">        &lt;<span class="hljs-title">div</span> <span class="hljs-title">class</span>="<span class="hljs-title">row</span> <span class="hljs-title">main</span>-<span class="hljs-title">imgbox</span>"&gt;</span></div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="41"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line"><span class="hljs-class">          @<span class="hljs-title">foreach</span>($<span class="hljs-title">adv</span> <span class="hljs-title">as</span> $<span class="hljs-title">adval</span>)</span></div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="42"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line"><span class="hljs-class">            &lt;<span class="hljs-title">div</span> <span class="hljs-title">class</span>="<span class="hljs-title">col</span>-<span class="hljs-title">md</span>-6"&gt;</span></div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="43"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line"><span class="hljs-class">              &lt;<span class="hljs-title">a</span> <span class="hljs-title">href</span>="#"&gt;&lt;<span class="hljs-title">img</span> <span class="hljs-title">class</span>="<span class="hljs-title">img</span>-<span class="hljs-title">fluid</span>" <span class="hljs-title">src</span>="/<span class="hljs-title">static</span>/<span class="hljs-title">upload</span>/</span>{{<span class="hljs-variable">$adval</span>}}<span class="hljs-string"><span class="hljs-string">"&gt;&lt;/a&gt;</span></span></div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="44"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line"><span class="hljs-string">            &lt;/div&gt;</span></div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="45"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line"><span class="hljs-string">          @endforeach</span></div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="46"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line"><span class="hljs-string">        &lt;/div&gt;</span></div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="47"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line"><span class="hljs-string">      &lt;/div&gt;</span></div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="48"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line"><span class="hljs-string">    &lt;/div&gt;</span></div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="49"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line"><span class="hljs-string">    &lt;div class="</span>row<span class="hljs-string"><span class="hljs-string">"&gt;</span></span></div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="50"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line"><span class="hljs-string">      &lt;div class="</span>col-md-<span class="hljs-number">9</span><span class="hljs-string"><span class="hljs-string">"&gt;</span></span></div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="51"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line"><span class="hljs-string">        &lt;div class="</span>row<span class="hljs-string"><span class="hljs-string">"&gt;</span></span></div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="52"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line"><span class="hljs-string">          &lt;!-- 栏目内容 --&gt;</span></div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="53"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line"><span class="hljs-string">          @foreach(<span class="hljs-subst">$list</span> as <span class="hljs-subst">$value</span>)</span></div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="54"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line"><span class="hljs-string">          &lt;div class="</span>col-md-<span class="hljs-number">6</span> mb-<span class="hljs-number">4</span><span class="hljs-string"><span class="hljs-string">"&gt;</span></span></div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="55"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line"><span class="hljs-string">            &lt;div class="</span>card main-card<span class="hljs-string"><span class="hljs-string">"&gt;</span></span></div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="56"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line"><span class="hljs-string">              &lt;div class="</span>card-header<span class="hljs-string"><span class="hljs-string">"&gt;</span></span></div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="57"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line"><span class="hljs-string">                &lt;h2&gt;{<span class="hljs-subst">{$value-&gt;name}</span>}&lt;/h2&gt;</span></div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="58"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line"><span class="hljs-string">                &lt;span class="</span><span class="hljs-keyword">float</span>-right<span class="hljs-string"><span class="hljs-string">"&gt;</span></span></div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="59"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line"><span class="hljs-string">                  &lt;a href="</span>{{ <span class="hljs-title function_ invoke__">url</span>(<span class="hljs-string">'lists'</span>, [<span class="hljs-string">'id'</span> =&gt; <span class="hljs-variable">$value</span>-&gt;id ])}}<span class="hljs-string"><span class="hljs-string">"&gt;[ 查看更多 ]&lt;/a&gt;</span></span></div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="60"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line"><span class="hljs-string">                &lt;/span&gt;</span></div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="61"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line"><span class="hljs-string">              &lt;/div&gt;</span></div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="62"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line"><span class="hljs-string">              @foreach(<span class="hljs-subst">$value</span>-&gt;content as <span class="hljs-subst">$val</span>)</span></div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="63"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line"><span class="hljs-string">              &lt;div class="</span>card-body<span class="hljs-string"><span class="hljs-string">"&gt;</span></span></div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="64"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line"><span class="hljs-string">                &lt;div class="</span>main-card-pic<span class="hljs-string"><span class="hljs-string">"&gt;</span></span></div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="65"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line"><span class="hljs-string">                  &lt;a href="</span>{{<span class="hljs-title function_ invoke__">url</span>(<span class="hljs-string">'detail'</span>, [<span class="hljs-string">'id'</span>=&gt; <span class="hljs-variable">$val</span>-&gt;id])}}<span class="hljs-string"><span class="hljs-string">"&gt;</span></span></div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="66"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line"><span class="hljs-string">                    &lt;img class="</span>img-fluid<span class="hljs-string">" src="</span>/<span class="hljs-built_in">static</span>/upload/{{<span class="hljs-variable">$val</span>-&gt;image}}<span class="hljs-string"><span class="hljs-string">"&gt;</span></span></div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="67"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line"><span class="hljs-string">                    &lt;span&gt;&lt;i class="</span>fa fa-search<span class="hljs-string"><span class="hljs-string">"&gt;&lt;/i&gt;&lt;/span&gt;</span></span></div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="68"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line"><span class="hljs-string">                  &lt;/a&gt;</span></div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="69"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line"><span class="hljs-string">                &lt;/div&gt;</span></div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="70"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line"><span class="hljs-string">                &lt;div class="</span>main-card-info<span class="hljs-string"><span class="hljs-string">"&gt;</span></span></div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="71"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line"><span class="hljs-string">                  &lt;span&gt;&lt;i class="</span>fa fa-calendar<span class="hljs-string"><span class="hljs-string">"&gt;&lt;/i&gt;</span></span></div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="72"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line"><span class="hljs-string">                  {{ date('Y-m-d', strtotime(<span class="hljs-subst">$val</span>-&gt;created_at)) }}&lt;/span&gt;</span></div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="73"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line"><span class="hljs-string">                &lt;/div&gt;</span></div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="74"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line"><span class="hljs-string">                &lt;h3&gt;&lt;a href="</span>{{<span class="hljs-title function_ invoke__">url</span>(<span class="hljs-string">'detail'</span>, [<span class="hljs-string">'id'</span>=&gt; <span class="hljs-variable">$val</span>-&gt;id])}}<span class="hljs-string"><span class="hljs-string">"&gt;{<span class="hljs-subst">{$val-&gt;title}</span>}&lt;/a&gt;&lt;/h3&gt;</span></span></div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="75"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line"><span class="hljs-string">                &lt;div class="</span>main-card-desc<span class="hljs-string"><span class="hljs-string">"&gt;{!!str_limit(<span class="hljs-subst">$val</span>-&gt;content , 100)!!}&lt;/div&gt;</span></span></div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="76"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line"><span class="hljs-string">              &lt;/div&gt;</span></div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="77"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line"><span class="hljs-string">              @endforeach</span></div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="78"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line"><span class="hljs-string">            &lt;/div&gt;</span></div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="79"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line"><span class="hljs-string">          &lt;/div&gt;</span></div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="80"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line"><span class="hljs-string">          @endforeach</span></div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="81"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line"><span class="hljs-string">        &lt;/div&gt;</span></div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="82"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line"><span class="hljs-string">      &lt;/div&gt;</span></div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="83"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line"><span class="hljs-string">      &lt;div class="</span>col-md-<span class="hljs-number">3</span><span class="hljs-string"><span class="hljs-string">"&gt;</span></span></div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="84"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line"><span class="hljs-string">        &lt;!-- 侧边栏 --&gt;</span></div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="85"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line"><span class="hljs-string">        @include('public/sidebar')</span></div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="86"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line"><span class="hljs-string">      &lt;/div&gt;</span></div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="87"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line"><span class="hljs-string">    &lt;/div&gt;</span></div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="88"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line"><span class="hljs-string">  &lt;/div&gt;</span></div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="89"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line"><span class="hljs-string">&lt;/div&gt;</span></div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="90"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line"><span class="hljs-string">@include('public/footer')</span></div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="91"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line"><span class="hljs-string">&lt;/body&gt;</span></div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="92"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line"><span class="hljs-string">&lt;/html&gt;</span></div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="93"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line"><span class="hljs-string"></span></div></div></li></ol></code><div class="hljs-button {2}" data-title="复制" onclick="hljs.copyCode(event)"></div></pre> 
<p>（2）创建Index控制器，具体代码如下：</p> 
<pre data-index="130" class="set-code-show" name="code"><code class="language-php hljs">php artisan make:controller IndexController</code><div class="hljs-button {2}" data-title="复制" onclick="hljs.copyCode(event)"></div></pre> 
<p>(3)在控制器中添加方法，具体代码如下：</p> 
<pre data-index="131" class="set-code-show" name="code"><code class="language-php hljs"><ol class="hljs-ln hundred" style="width:1042px"><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="1"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line"><span class="hljs-meta">&lt;?php</span></div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="2"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line"> </div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="3"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line"><span class="hljs-keyword">namespace</span> <span class="hljs-title class_">App</span>\<span class="hljs-title class_">Http</span>\<span class="hljs-title class_">Controllers</span>;</div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="4"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line"> </div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="5"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line"><span class="hljs-keyword">use</span> <span class="hljs-title">Illuminate</span>\<span class="hljs-title">Http</span>\<span class="hljs-title">Request</span>;</div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="6"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line"><span class="hljs-keyword">use</span> <span class="hljs-title">App</span>\<span class="hljs-title">Category</span>;</div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="7"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line"><span class="hljs-keyword">use</span> <span class="hljs-title">App</span>\<span class="hljs-title">Content</span>;</div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="8"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line"><span class="hljs-keyword">use</span> <span class="hljs-title">App</span>\<span class="hljs-title">Adv</span>;</div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="9"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line"><span class="hljs-keyword">use</span> <span class="hljs-title">App</span>\<span class="hljs-title">Like</span>;</div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="10"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line"><span class="hljs-keyword">use</span> <span class="hljs-title">App</span>\<span class="hljs-title">Comment</span>;</div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="11"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line"><span class="hljs-keyword">use</span> <span class="hljs-title">Illuminate</span>\<span class="hljs-title">Support</span>\<span class="hljs-title">Facades</span>\<span class="hljs-title">DB</span>;</div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="12"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line"> </div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="13"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line"><span class="hljs-class"><span class="hljs-keyword">class</span> <span class="hljs-title">IndexController</span> <span class="hljs-keyword">extends</span> <span class="hljs-title">Controller</span></span></div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="14"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line">{</div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="15"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line">    <span class="hljs-keyword">public</span> <span class="hljs-function"><span class="hljs-keyword">function</span> <span class="hljs-title">index</span>(<span class="hljs-params"></span>)</span></div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="16"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line">    {</div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="17"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line">        <span class="hljs-variable language_">$this</span>-&gt;<span class="hljs-title function_ invoke__">navBar</span>();</div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="18"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line">        <span class="hljs-variable language_">$this</span>-&gt;<span class="hljs-title function_ invoke__">hotContent</span>();</div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="19"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line">        <span class="hljs-variable">$recommend</span> = <span class="hljs-title class_">Content</span>::<span class="hljs-title function_ invoke__">where</span>(<span class="hljs-string">'status'</span>, <span class="hljs-string">'2'</span>)-&gt;<span class="hljs-title function_ invoke__">get</span>();   <span class="hljs-comment">// 新增代码</span></div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="20"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line">        <span class="hljs-variable">$advcontent</span> = [];</div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="21"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line">        <span class="hljs-variable">$advlist</span> = <span class="hljs-title class_">Adv</span>::<span class="hljs-title function_ invoke__">where</span>(<span class="hljs-string">'name'</span>, <span class="hljs-string">'imgbox'</span>)-&gt;<span class="hljs-title function_ invoke__">get</span>();</div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="22"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line">        <span class="hljs-keyword">foreach</span> (<span class="hljs-variable">$advlist</span> <span class="hljs-keyword">as</span> <span class="hljs-variable">$key</span> =&gt; <span class="hljs-variable">$value</span>) {</div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="23"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line">            <span class="hljs-keyword">foreach</span> (<span class="hljs-variable">$value</span>-&gt;content <span class="hljs-keyword">as</span> <span class="hljs-variable">$k</span> =&gt; <span class="hljs-variable">$v</span>) {</div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="24"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line">                <span class="hljs-variable">$advcontent</span>= <span class="hljs-title function_ invoke__">explode</span>(<span class="hljs-string">'|'</span>, <span class="hljs-variable">$v</span>-&gt;path);</div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="25"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line">            }</div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="26"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line">        }</div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="27"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line">        <span class="hljs-variable">$list</span> = <span class="hljs-title class_">Category</span>::<span class="hljs-title function_ invoke__">orderBy</span>(<span class="hljs-string">'id'</span>, <span class="hljs-string">'desc'</span>)-&gt;<span class="hljs-title function_ invoke__">get</span>()-&gt;<span class="hljs-title function_ invoke__">take</span>(<span class="hljs-number">4</span>);</div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="28"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line">        <span class="hljs-keyword">return</span> <span class="hljs-title function_ invoke__">view</span>(<span class="hljs-string">'index'</span>, [<span class="hljs-string">'recommend'</span> =&gt; <span class="hljs-variable">$recommend</span>, <span class="hljs-string">'adv'</span> =&gt; <span class="hljs-variable">$advcontent</span>, <span class="hljs-string">'list'</span> =&gt; <span class="hljs-variable">$list</span>]);</div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="29"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line"> </div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="30"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line">    }</div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="31"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line"> </div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="32"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line">    <span class="hljs-keyword">protected</span> <span class="hljs-function"><span class="hljs-keyword">function</span> <span class="hljs-title">navBar</span>(<span class="hljs-params"></span>)</span>{</div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="33"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line">        <span class="hljs-variable">$data</span> = <span class="hljs-title class_">Category</span>::<span class="hljs-title function_ invoke__">orderBy</span>(<span class="hljs-string">'sort'</span>, <span class="hljs-string">'asc'</span>)-&gt;<span class="hljs-title function_ invoke__">get</span>()-&gt;<span class="hljs-title function_ invoke__">toArray</span>();</div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="34"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line">        <span class="hljs-variable">$category</span> = <span class="hljs-variable">$sub</span> = [];</div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="35"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line">        <span class="hljs-keyword">foreach</span>(<span class="hljs-variable">$data</span> <span class="hljs-keyword">as</span> <span class="hljs-variable">$k</span>=&gt;<span class="hljs-variable">$v</span>){</div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="36"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line">            <span class="hljs-keyword">if</span> (<span class="hljs-variable">$v</span>[<span class="hljs-string">'pid'</span>] != <span class="hljs-number">0</span>) {</div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="37"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line">                <span class="hljs-variable">$sub</span>[<span class="hljs-variable">$v</span>[<span class="hljs-string">'id'</span>]] = <span class="hljs-variable">$v</span>;</div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="38"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line">            }</div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="39"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line">        }</div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="40"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line">        <span class="hljs-keyword">foreach</span>(<span class="hljs-variable">$data</span> <span class="hljs-keyword">as</span> <span class="hljs-variable">$key</span>=&gt;<span class="hljs-variable">$val</span>){</div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="41"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line">            <span class="hljs-keyword">if</span> (<span class="hljs-variable">$val</span>[<span class="hljs-string">'pid'</span>] == <span class="hljs-number">0</span>) {</div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="42"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line">                <span class="hljs-variable">$category</span>[<span class="hljs-variable">$key</span>] = <span class="hljs-variable">$val</span>;</div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="43"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line">            }</div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="44"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line">            <span class="hljs-keyword">foreach</span>(<span class="hljs-variable">$sub</span> <span class="hljs-keyword">as</span> <span class="hljs-variable">$subv</span>) {</div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="45"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line">                <span class="hljs-keyword">if</span> (<span class="hljs-variable">$subv</span>[<span class="hljs-string">'pid'</span>] == <span class="hljs-variable">$val</span>[<span class="hljs-string">'id'</span>]) {</div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="46"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line">                    <span class="hljs-variable">$category</span>[<span class="hljs-variable">$key</span>][<span class="hljs-string">'sub'</span>][] = <span class="hljs-variable">$subv</span>;</div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="47"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line">                }</div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="48"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line">            }</div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="49"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line">        }</div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="50"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line">        <span class="hljs-keyword">return</span> <span class="hljs-title function_ invoke__">view</span>()-&gt;<span class="hljs-title function_ invoke__">share</span>(<span class="hljs-string">'category'</span>, <span class="hljs-variable">$category</span>);</div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="51"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line">    }</div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="52"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line"> </div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="53"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line">    <span class="hljs-keyword">public</span> <span class="hljs-function"><span class="hljs-keyword">function</span> <span class="hljs-title">lists</span>(<span class="hljs-params"><span class="hljs-variable">$id</span></span>)</span></div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="54"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line">    {</div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="55"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line">        <span class="hljs-keyword">if</span>(!<span class="hljs-variable">$id</span>){</div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="56"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line">            <span class="hljs-keyword">return</span> <span class="hljs-title function_ invoke__">redirect</span>(<span class="hljs-string">'/'</span>)-&gt;<span class="hljs-title function_ invoke__">with</span>(<span class="hljs-string">'tip'</span>,<span class="hljs-string">'缺少参数'</span>);</div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="57"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line">        }</div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="58"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line">        <span class="hljs-variable language_">$this</span>-&gt;<span class="hljs-title function_ invoke__">navBar</span>();</div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="59"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line">        <span class="hljs-variable language_">$this</span>-&gt;<span class="hljs-title function_ invoke__">hotContent</span>();</div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="60"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line">        <span class="hljs-variable">$content</span> = <span class="hljs-title class_">Content</span>::<span class="hljs-title function_ invoke__">where</span>(<span class="hljs-string">'cid'</span>, <span class="hljs-variable">$id</span>)-&gt;<span class="hljs-title function_ invoke__">paginate</span>(<span class="hljs-number">4</span>);</div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="61"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line">        <span class="hljs-keyword">return</span> <span class="hljs-title function_ invoke__">view</span>(<span class="hljs-string">'lists'</span>, [<span class="hljs-string">'id'</span> =&gt; <span class="hljs-variable">$id</span>, <span class="hljs-string">'content'</span> =&gt; <span class="hljs-variable">$content</span>]);</div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="62"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line">    }</div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="63"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line"> </div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="64"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line">    <span class="hljs-keyword">public</span> <span class="hljs-function"><span class="hljs-keyword">function</span> <span class="hljs-title">detail</span>(<span class="hljs-params"><span class="hljs-variable">$id</span></span>)</span></div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="65"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line">    {</div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="66"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line">        <span class="hljs-keyword">if</span>(!<span class="hljs-variable">$id</span>){</div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="67"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line">            <span class="hljs-keyword">return</span> <span class="hljs-title function_ invoke__">redirect</span>(<span class="hljs-string">'/'</span>)-&gt;<span class="hljs-title function_ invoke__">with</span>(<span class="hljs-string">'tip'</span>,<span class="hljs-string">'缺少参数'</span>);</div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="68"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line">        }</div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="69"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line">        <span class="hljs-variable language_">$this</span>-&gt;<span class="hljs-title function_ invoke__">navBar</span>();</div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="70"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line">        <span class="hljs-variable language_">$this</span>-&gt;<span class="hljs-title function_ invoke__">hotContent</span>();</div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="71"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line">        <span class="hljs-variable">$content</span> = <span class="hljs-title class_">Content</span>::<span class="hljs-title function_ invoke__">find</span>(<span class="hljs-variable">$id</span>);</div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="72"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line">        <span class="hljs-variable">$count</span> = <span class="hljs-title class_">Like</span>::<span class="hljs-title function_ invoke__">where</span>(<span class="hljs-string">'cid'</span>, <span class="hljs-variable">$id</span>)-&gt;<span class="hljs-title function_ invoke__">get</span>()-&gt;<span class="hljs-title function_ invoke__">count</span>();</div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="73"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line">        <span class="hljs-variable">$comments</span> = <span class="hljs-title class_">Comment</span>::<span class="hljs-title function_ invoke__">where</span>(<span class="hljs-string">'cid'</span>, <span class="hljs-variable">$id</span>)-&gt;<span class="hljs-title function_ invoke__">get</span>();</div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="74"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line">        <span class="hljs-keyword">return</span> <span class="hljs-title function_ invoke__">view</span>(<span class="hljs-string">'detail'</span>, [<span class="hljs-string">'id'</span> =&gt; <span class="hljs-variable">$content</span>-&gt;id, <span class="hljs-string">'cid'</span> =&gt; <span class="hljs-variable">$content</span>-&gt;cid,</div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="75"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line">            <span class="hljs-string">'content'</span> =&gt; <span class="hljs-variable">$content</span>, <span class="hljs-string">'count'</span> =&gt; <span class="hljs-variable">$count</span>, <span class="hljs-string">'comments'</span> =&gt; <span class="hljs-variable">$comments</span>]);</div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="76"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line">    }</div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="77"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line"> </div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="78"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line">    <span class="hljs-keyword">public</span> <span class="hljs-function"><span class="hljs-keyword">function</span> <span class="hljs-title">like</span>(<span class="hljs-params"><span class="hljs-variable">$id</span></span>)</span></div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="79"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line">    {</div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="80"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line">        <span class="hljs-keyword">if</span>(!<span class="hljs-variable">$id</span>){</div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="81"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line">            <span class="hljs-keyword">return</span> <span class="hljs-title function_ invoke__">response</span>()-&gt;<span class="hljs-title function_ invoke__">json</span>([<span class="hljs-string">'status'</span>=&gt;<span class="hljs-string">'2'</span>,<span class="hljs-string">'msg'</span>=&gt;<span class="hljs-string">'缺少参数'</span>]);</div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="82"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line">        }</div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="83"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line">        @<span class="hljs-title function_ invoke__">session_start</span>();</div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="84"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line">        <span class="hljs-variable">$data</span> = <span class="hljs-keyword">array</span>(</div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="85"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line">            <span class="hljs-string">'uid'</span> =&gt; <span class="hljs-title function_ invoke__">session</span>()-&gt;<span class="hljs-title function_ invoke__">get</span>(<span class="hljs-string">'users.id'</span>),</div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="86"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line">            <span class="hljs-string">'cid'</span> =&gt; <span class="hljs-variable">$id</span></div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="87"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line">        );</div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="88"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line">        <span class="hljs-variable">$re</span> = <span class="hljs-title class_">Like</span>::<span class="hljs-title function_ invoke__">create</span>(<span class="hljs-variable">$data</span>);</div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="89"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line">        <span class="hljs-keyword">if</span>(<span class="hljs-variable">$re</span>){</div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="90"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line">            <span class="hljs-variable">$count</span> = <span class="hljs-title class_">Like</span>::<span class="hljs-title function_ invoke__">where</span>(<span class="hljs-string">'cid'</span>, <span class="hljs-variable">$id</span>)-&gt;<span class="hljs-title function_ invoke__">get</span>()-&gt;<span class="hljs-title function_ invoke__">count</span>();</div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="91"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line">            <span class="hljs-keyword">return</span> <span class="hljs-title function_ invoke__">response</span>()-&gt;<span class="hljs-title function_ invoke__">json</span>([<span class="hljs-string">'status'</span>=&gt;<span class="hljs-string">'1'</span>, <span class="hljs-string">'msg'</span>=&gt;<span class="hljs-string">'点赞成功'</span>, <span class="hljs-string">'count'</span>=&gt;<span class="hljs-variable">$count</span>]);</div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="92"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line">        }<span class="hljs-keyword">else</span>{</div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="93"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line">            <span class="hljs-keyword">return</span> <span class="hljs-title function_ invoke__">response</span>()-&gt;<span class="hljs-title function_ invoke__">json</span>([<span class="hljs-string">'status'</span>=&gt;<span class="hljs-string">'2'</span>, <span class="hljs-string">'msg'</span>=&gt;<span class="hljs-string">'点赞失败'</span>]);</div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="94"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line">        }</div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="95"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line">    }</div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="96"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line"> </div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="97"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line">    <span class="hljs-keyword">public</span> <span class="hljs-function"><span class="hljs-keyword">function</span> <span class="hljs-title">comment</span>(<span class="hljs-params">Request <span class="hljs-variable">$request</span></span>)</span></div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="98"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line">    {</div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="99"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line">        <span class="hljs-variable">$cid</span> = <span class="hljs-variable">$request</span>-&gt;<span class="hljs-title function_ invoke__">input</span>(<span class="hljs-string">'cid'</span>);</div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="100"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line">        <span class="hljs-variable">$content</span> = <span class="hljs-variable">$request</span>-&gt;<span class="hljs-title function_ invoke__">input</span>(<span class="hljs-string">'content'</span>);</div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="101"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line">        <span class="hljs-variable">$uid</span> = <span class="hljs-title function_ invoke__">session</span>()-&gt;<span class="hljs-title function_ invoke__">get</span>(<span class="hljs-string">'users.id'</span>);</div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="102"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line">        <span class="hljs-keyword">if</span>(!<span class="hljs-variable">$content</span>){</div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="103"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line">            <span class="hljs-keyword">return</span> <span class="hljs-title function_ invoke__">response</span>()-&gt;<span class="hljs-title function_ invoke__">json</span>([<span class="hljs-string">'status'</span>=&gt;<span class="hljs-string">'2'</span>, <span class="hljs-string">'msg'</span>=&gt;<span class="hljs-string">'缺少参数'</span>]);</div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="104"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line">        }</div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="105"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line">        <span class="hljs-variable">$data</span> = <span class="hljs-keyword">array</span>(</div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="106"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line">            <span class="hljs-string">'uid'</span> =&gt; <span class="hljs-variable">$uid</span>,</div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="107"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line">            <span class="hljs-string">'cid'</span> =&gt; <span class="hljs-variable">$cid</span>,</div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="108"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line">            <span class="hljs-string">'content'</span> =&gt; <span class="hljs-variable">$content</span>,</div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="109"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line">        );</div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="110"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line">        <span class="hljs-variable">$re</span> = <span class="hljs-title class_">Comment</span>::<span class="hljs-title function_ invoke__">create</span>(<span class="hljs-variable">$data</span>);</div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="111"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line">        <span class="hljs-keyword">if</span> (<span class="hljs-variable">$re</span>) {</div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="112"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line">            <span class="hljs-variable">$theComment</span> = <span class="hljs-title class_">Comment</span>::<span class="hljs-title function_ invoke__">where</span>(<span class="hljs-string">'cid'</span>, <span class="hljs-variable">$cid</span>)-&gt;<span class="hljs-title function_ invoke__">where</span>(<span class="hljs-string">'uid'</span>, <span class="hljs-variable">$uid</span>)-&gt;<span class="hljs-title function_ invoke__">orderBy</span>(<span class="hljs-string">'id'</span>,<span class="hljs-string">'desc'</span>)-&gt;<span class="hljs-title function_ invoke__">first</span>();</div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="113"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line">            <span class="hljs-variable">$theComment</span>-&gt;created_time = <span class="hljs-title function_ invoke__">date</span>(<span class="hljs-string">'Y-m-d'</span>, <span class="hljs-title function_ invoke__">strtotime</span>(<span class="hljs-variable">$theComment</span>-&gt;created_at));</div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="114"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line">            <span class="hljs-variable">$count</span> = <span class="hljs-title class_">Comment</span>::<span class="hljs-title function_ invoke__">where</span>(<span class="hljs-string">'cid'</span>, <span class="hljs-variable">$cid</span>)-&gt;<span class="hljs-title function_ invoke__">get</span>()-&gt;<span class="hljs-title function_ invoke__">count</span>();</div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="115"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line">            <span class="hljs-variable">$theComment</span>-&gt;count = <span class="hljs-variable">$count</span>;</div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="116"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line">            <span class="hljs-variable">$theComment</span>-&gt;user = <span class="hljs-variable">$theComment</span>-&gt;user-&gt;name;</div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="117"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line">            <span class="hljs-keyword">return</span> <span class="hljs-title function_ invoke__">response</span>()-&gt;<span class="hljs-title function_ invoke__">json</span>([<span class="hljs-string">'status'</span> =&gt; <span class="hljs-string">'1'</span>, <span class="hljs-string">'msg'</span> =&gt; <span class="hljs-string">'评论成功'</span>,</div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="118"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line">                <span class="hljs-string">'data'</span> =&gt; <span class="hljs-variable">$theComment</span>]);</div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="119"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line">        } <span class="hljs-keyword">else</span> {</div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="120"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line">            <span class="hljs-keyword">return</span> <span class="hljs-title function_ invoke__">response</span>()-&gt;<span class="hljs-title function_ invoke__">json</span>([<span class="hljs-string">'status'</span> =&gt; <span class="hljs-string">'2'</span>, <span class="hljs-string">'msg'</span> =&gt; <span class="hljs-string">'评论失败'</span>]);</div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="121"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line">        }</div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="122"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line"> </div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="123"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line">    }</div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="124"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line"> </div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="125"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line">    <span class="hljs-keyword">protected</span> <span class="hljs-function"><span class="hljs-keyword">function</span> <span class="hljs-title">hotContent</span>(<span class="hljs-params"></span>)</span>{</div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="126"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line">        <span class="hljs-variable">$hotContent</span> = <span class="hljs-title class_">Like</span>::<span class="hljs-title function_ invoke__">select</span>(<span class="hljs-string">'cid'</span>,DB::<span class="hljs-title function_ invoke__">raw</span>(<span class="hljs-string">'count(*) as num'</span>))-&gt;<span class="hljs-title function_ invoke__">orderBy</span>(<span class="hljs-string">'num'</span>, <span class="hljs-string">'desc'</span>)-&gt;<span class="hljs-title function_ invoke__">groupBy</span>(<span class="hljs-string">'cid'</span>)-&gt;<span class="hljs-title function_ invoke__">get</span>()-&gt;<span class="hljs-title function_ invoke__">take</span>(<span class="hljs-number">2</span>);</div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="127"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line">        <span class="hljs-keyword">return</span> <span class="hljs-title function_ invoke__">view</span>()-&gt;<span class="hljs-title function_ invoke__">share</span>(<span class="hljs-string">'hotContent'</span>, <span class="hljs-variable">$hotContent</span>);</div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="128"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line">    }</div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="129"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line"> </div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="130"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line"> </div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="131"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line">}</div></div></li></ol></code><div class="hljs-button {2}" data-title="复制" onclick="hljs.copyCode(event)"></div></pre> 
<p>（4）在<strong>routes\web.php</strong>文件中添加路由规则，具体代码如下：</p> 
<pre data-index="132" class="set-code-show" name="code"><code class="language-php hljs"><ol class="hljs-ln" style="width:100%"><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="1"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line"><span class="hljs-comment">// 首页</span></div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="2"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line"><span class="hljs-title class_">Route</span>::<span class="hljs-title function_ invoke__">get</span>(<span class="hljs-string">'/'</span>, <span class="hljs-string">'IndexController@index'</span>);</div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="3"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line"><span class="hljs-title class_">Route</span>::<span class="hljs-title function_ invoke__">get</span>(<span class="hljs-string">'/lists/{id}'</span>, <span class="hljs-string">'IndexController@lists'</span>);</div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="4"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line"><span class="hljs-title class_">Route</span>::<span class="hljs-title function_ invoke__">get</span>(<span class="hljs-string">'/detail/{id}'</span>, <span class="hljs-string">'IndexController@detail'</span>);</div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="5"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line"><span class="hljs-title class_">Route</span>::<span class="hljs-title function_ invoke__">get</span>(<span class="hljs-string">'/like/{id}'</span>, <span class="hljs-string">'IndexController@like'</span>);</div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="6"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line"><span class="hljs-title class_">Route</span>::<span class="hljs-title function_ invoke__">get</span>(<span class="hljs-string">'/comment'</span>, <span class="hljs-string">'IndexController@comment'</span>);</div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="7"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line"><span class="hljs-title class_">Route</span>::<span class="hljs-title function_ invoke__">post</span>(<span class="hljs-string">'/register'</span>, <span class="hljs-string">'UserController@register'</span>);</div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="8"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line"><span class="hljs-title class_">Route</span>::<span class="hljs-title function_ invoke__">post</span>(<span class="hljs-string">'/login'</span>, <span class="hljs-string">'UserController@login'</span>);</div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="9"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line"><span class="hljs-title class_">Route</span>::<span class="hljs-title function_ invoke__">get</span>(<span class="hljs-string">'/logout'</span>, <span class="hljs-string">'UserController@logout'</span>);</div></div></li></ol></code><div class="hljs-button {2}" data-title="复制" onclick="hljs.copyCode(event)"></div></pre> 
<p>（5）修改<strong>app\Adv.php</strong>，设置关联模型，具体代码如下：</p> 
<pre data-index="133" class="set-code-show" name="code"><code class="language-php hljs"><ol class="hljs-ln" style="width:100%"><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="1"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line"><span class="hljs-meta">&lt;?php</span></div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="2"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line"> </div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="3"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line"><span class="hljs-keyword">namespace</span> <span class="hljs-title class_">App</span>;</div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="4"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line"> </div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="5"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line"><span class="hljs-keyword">use</span> <span class="hljs-title">Illuminate</span>\<span class="hljs-title">Database</span>\<span class="hljs-title">Eloquent</span>\<span class="hljs-title">Model</span>;</div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="6"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line"> </div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="7"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line"><span class="hljs-class"><span class="hljs-keyword">class</span> <span class="hljs-title">Adv</span> <span class="hljs-keyword">extends</span> <span class="hljs-title">Model</span></span></div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="8"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line">{</div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="9"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line">    <span class="hljs-keyword">protected</span> <span class="hljs-variable">$table</span> = <span class="hljs-string">"adv"</span>;</div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="10"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line">    <span class="hljs-keyword">public</span> <span class="hljs-variable">$fillable</span> = [<span class="hljs-string">'name'</span>];</div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="11"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line"> </div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="12"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line">    <span class="hljs-keyword">public</span> <span class="hljs-function"><span class="hljs-keyword">function</span> <span class="hljs-title">content</span>(<span class="hljs-params"></span>)</span></div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="13"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line">    {</div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="14"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line">        <span class="hljs-keyword">return</span> <span class="hljs-variable language_">$this</span>-&gt;<span class="hljs-title function_ invoke__">hasMany</span>(<span class="hljs-string">'App\Advcontent'</span>, <span class="hljs-string">'advid'</span>, <span class="hljs-string">'id'</span>);</div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="15"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line">    }</div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="16"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line"> </div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="17"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line">}</div></div></li></ol></code><div class="hljs-button {2}" data-title="复制" onclick="hljs.copyCode(event)"></div></pre> 
<p>（6）修改<strong>app\Category.php</strong>，设置关联模型，具体代码如下：</p> 
<pre data-index="134" class="set-code-show" name="code"><code class="language-php hljs"><ol class="hljs-ln" style="width:100%"><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="1"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line"><span class="hljs-meta">&lt;?php</span></div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="2"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line"> </div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="3"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line"><span class="hljs-keyword">namespace</span> <span class="hljs-title class_">App</span>;</div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="4"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line"> </div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="5"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line"><span class="hljs-keyword">use</span> <span class="hljs-title">Illuminate</span>\<span class="hljs-title">Database</span>\<span class="hljs-title">Eloquent</span>\<span class="hljs-title">Model</span>;</div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="6"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line"> </div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="7"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line"><span class="hljs-class"><span class="hljs-keyword">class</span> <span class="hljs-title">Category</span> <span class="hljs-keyword">extends</span> <span class="hljs-title">Model</span></span></div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="8"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line">{</div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="9"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line">    <span class="hljs-keyword">protected</span> <span class="hljs-variable">$table</span> = <span class="hljs-string">"category"</span>;</div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="10"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line">    <span class="hljs-keyword">public</span> <span class="hljs-variable">$fillable</span> = [<span class="hljs-string">'pid'</span>, <span class="hljs-string">'name'</span>, <span class="hljs-string">'sort'</span>];</div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="11"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line">    <span class="hljs-keyword">public</span> <span class="hljs-function"><span class="hljs-keyword">function</span> <span class="hljs-title">content</span>(<span class="hljs-params"></span>)</span></div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="12"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line">    {</div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="13"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line">        <span class="hljs-keyword">return</span> <span class="hljs-variable language_">$this</span>-&gt;<span class="hljs-title function_ invoke__">hasMany</span>(<span class="hljs-string">'App\Content'</span>, <span class="hljs-string">'cid'</span>, <span class="hljs-string">'id'</span>)-&gt;<span class="hljs-title function_ invoke__">orderBy</span>(<span class="hljs-string">'id'</span>, <span class="hljs-string">'desc'</span>)-&gt;<span class="hljs-title function_ invoke__">limit</span>(<span class="hljs-number">1</span>);</div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="14"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line">    }</div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="15"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line">}</div></div></li></ol></code><div class="hljs-button {2}" data-title="复制" onclick="hljs.copyCode(event)"></div></pre> 
<p>(7)通过浏览器访问，看看是否完整显示。</p> 
<h3 id="%E5%89%8D%E5%8F%B0%E7%94%A8%E6%88%B7%E7%AE%A1%E7%90%86"><a name="t39"></a>前台用户管理</h3> 
<h4 id="%E7%94%A8%E6%88%B7%E6%B3%A8%E5%86%8C%E3%80%81%E7%94%A8%E6%88%B7%E7%99%BB%E5%BD%95%E5%92%8C%E7%94%A8%E6%88%B7%E9%80%80%E5%87%BA"><a name="t40"></a>用户注册、用户登录和用户退出</h4> 
<p>(1)在<strong>header.blade.php</strong>视图中添加注册表单、登录表单，具体代码如下：</p> 
<pre data-index="135" class="set-code-show" name="code"><code class="language-php hljs"><ol class="hljs-ln hundred" style="width:1651px"><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="1"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line">&lt;div <span class="hljs-class"><span class="hljs-class"><span class="hljs-keyword">class</span>="<span class="hljs-title">header</span>"&gt;</span></span></div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="2"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line"><span class="hljs-class">  &lt;<span class="hljs-title">header</span>&gt;</span></div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="3"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line"><span class="hljs-class">    &lt;<span class="hljs-title">div</span> <span class="hljs-title">class</span>="<span class="hljs-title">container</span>"&gt;</span></div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="4"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line"><span class="hljs-class">      &lt;<span class="hljs-title">a</span> <span class="hljs-title">href</span>="</span>{{<span class="hljs-title function_ invoke__">url</span>(<span class="hljs-string">"/"</span>)}}<span class="hljs-string">" style="</span>color:<span class="hljs-comment">#000000"&gt;</span></div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="5"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line">        &lt;div <span class="hljs-class"><span class="hljs-class"><span class="hljs-keyword">class</span>="<span class="hljs-title">header</span>-<span class="hljs-title">logo</span>"&gt;&lt;<span class="hljs-title">span</span>&gt;内容&lt;/<span class="hljs-title">span</span>&gt;管理系统&lt;/<span class="hljs-title">div</span>&gt;</span></span></div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="6"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line"><span class="hljs-class">      &lt;/<span class="hljs-title">a</span>&gt;</span></div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="7"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line"><span class="hljs-class">      &lt;<span class="hljs-title">ul</span> <span class="hljs-title">class</span>="<span class="hljs-title">header</span>-<span class="hljs-title">right</span>"&gt;</span></div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="8"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line"><span class="hljs-class">        @<span class="hljs-title">if</span>(<span class="hljs-title">session</span>()-&gt;<span class="hljs-title">has</span>('<span class="hljs-title">users</span>.<span class="hljs-title">name</span>'))</span></div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="9"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line"><span class="hljs-class">          &lt;<span class="hljs-title">li</span>&gt;</span></div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="10"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line"><span class="hljs-class">            &lt;<span class="hljs-title">a</span> <span class="hljs-title">href</span>="#" <span class="hljs-title">class</span>="<span class="hljs-title">j</span>-<span class="hljs-title">layout</span>-<span class="hljs-title">pwd</span>"&gt;</span></div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="11"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line"><span class="hljs-class">              &lt;<span class="hljs-title">i</span> <span class="hljs-title">class</span>="<span class="hljs-title">fa</span> <span class="hljs-title">fa</span>-<span class="hljs-title">user</span> <span class="hljs-title">fa</span>-<span class="hljs-title">fw</span>"&gt;&lt;/<span class="hljs-title">i</span>&gt;</span>{{ <span class="hljs-title function_ invoke__">session</span>()-&gt;<span class="hljs-title function_ invoke__">get</span>(<span class="hljs-string">'users.name'</span>) }}</div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="12"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line">            &lt;/a&gt;</div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="13"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line">          &lt;/li&gt;</div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="14"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line">          &lt;li&gt;&lt;a href=<span class="hljs-string">"{{ url('logout') }}"</span>&gt;&lt;i <span class="hljs-class"><span class="hljs-class"><span class="hljs-keyword">class</span>="<span class="hljs-title">fa</span> <span class="hljs-title">fa</span>-<span class="hljs-title">power</span>-<span class="hljs-title">off</span> <span class="hljs-title">fa</span>-<span class="hljs-title">fw</span>"&gt;&lt;/<span class="hljs-title">i</span>&gt;退出&lt;/<span class="hljs-title">a</span>&gt;&lt;/<span class="hljs-title">li</span>&gt;</span></span></div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="15"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line"><span class="hljs-class">        @<span class="hljs-title">else</span></span></div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="16"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line"><span class="hljs-class">          &lt;<span class="hljs-title">li</span>&gt;&lt;<span class="hljs-title">a</span> <span class="hljs-title">href</span>="#" <span class="hljs-title">data</span>-<span class="hljs-title">toggle</span>="<span class="hljs-title">modal</span>" <span class="hljs-title">data</span>-<span class="hljs-title">target</span>="#<span class="hljs-title">loginModal</span>"&gt;登录&lt;/<span class="hljs-title">a</span>&gt;&lt;/<span class="hljs-title">li</span>&gt;</span></div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="17"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line"><span class="hljs-class">          &lt;<span class="hljs-title">li</span>&gt;&lt;<span class="hljs-title">a</span> <span class="hljs-title">href</span>="#" <span class="hljs-title">data</span>-<span class="hljs-title">toggle</span>="<span class="hljs-title">modal</span>" <span class="hljs-title">data</span>-<span class="hljs-title">target</span>="#<span class="hljs-title">registerModal</span>"&gt;注册&lt;/<span class="hljs-title">a</span>&gt;&lt;/<span class="hljs-title">li</span>&gt;</span></div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="18"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line"><span class="hljs-class">        @<span class="hljs-title">endif</span></span></div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="19"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line"><span class="hljs-class">      &lt;/<span class="hljs-title">ul</span>&gt;</span></div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="20"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line"><span class="hljs-class">    &lt;/<span class="hljs-title">div</span>&gt;</span></div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="21"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line"><span class="hljs-class">  &lt;/<span class="hljs-title">header</span>&gt;</span></div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="22"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line"><span class="hljs-class">  &lt;!-- 栏目列表 --&gt;</span></div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="23"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line"><span class="hljs-class">  &lt;<span class="hljs-title">nav</span> <span class="hljs-title">class</span>="<span class="hljs-title">navbar</span> <span class="hljs-title">navbar</span>-<span class="hljs-title">expand</span>-<span class="hljs-title">md</span> <span class="hljs-title">navbar</span>-<span class="hljs-title">dark</span>"&gt;</span></div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="24"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line"><span class="hljs-class">    &lt;<span class="hljs-title">div</span> <span class="hljs-title">class</span>="<span class="hljs-title">container</span>"&gt;</span></div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="25"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line"><span class="hljs-class">      &lt;<span class="hljs-title">div</span>&gt;&lt;/<span class="hljs-title">div</span>&gt;</span></div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="26"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line"><span class="hljs-class">      &lt;<span class="hljs-title">button</span> <span class="hljs-title">class</span>="<span class="hljs-title">navbar</span>-<span class="hljs-title">toggler</span>" <span class="hljs-title">type</span>="<span class="hljs-title">button</span>" <span class="hljs-title">data</span>-<span class="hljs-title">toggle</span>="<span class="hljs-title">collapse</span>" <span class="hljs-title">data</span>-<span class="hljs-title">target</span>="#<span class="hljs-title">navbarSupportedContent</span>" <span class="hljs-title">aria</span>-<span class="hljs-title">expanded</span>="<span class="hljs-title">false</span>" <span class="hljs-title">aria</span>-<span class="hljs-title">controls</span>="<span class="hljs-title">navbarSupportedContent</span>" <span class="hljs-title">aria</span>-<span class="hljs-title">label</span>="<span class="hljs-title">Toggle</span> <span class="hljs-title">navigation</span>"&gt;</span></div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="27"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line"><span class="hljs-class">        &lt;<span class="hljs-title">span</span> <span class="hljs-title">class</span>="<span class="hljs-title">navbar</span>-<span class="hljs-title">toggler</span>-<span class="hljs-title">icon</span>"&gt;&lt;/<span class="hljs-title">span</span>&gt;</span></div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="28"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line"><span class="hljs-class">      &lt;/<span class="hljs-title">button</span>&gt;</span></div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="29"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line"><span class="hljs-class">      &lt;<span class="hljs-title">div</span> <span class="hljs-title">class</span>="<span class="hljs-title">collapse</span> <span class="hljs-title">navbar</span>-<span class="hljs-title">collapse</span>" <span class="hljs-title">id</span>="<span class="hljs-title">navbarSupportedContent</span>"&gt;</span></div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="30"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line"><span class="hljs-class">        &lt;<span class="hljs-title">ul</span> <span class="hljs-title">class</span>="<span class="hljs-title">navbar</span>-<span class="hljs-title">nav</span> <span class="hljs-title">mr</span>-<span class="hljs-title">auto</span>"&gt;</span></div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="31"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line"><span class="hljs-class">          &lt;<span class="hljs-title">li</span> <span class="hljs-title">class</span>="<span class="hljs-title">nav</span>-<span class="hljs-title">item</span>"&gt;</span></div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="32"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line"><span class="hljs-class">            &lt;<span class="hljs-title">a</span> <span class="hljs-title">class</span>="<span class="hljs-title">nav</span>-<span class="hljs-title">link</span>" <span class="hljs-title">href</span>="/"&gt;首页&lt;/<span class="hljs-title">a</span>&gt;</span></div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="33"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line"><span class="hljs-class">          &lt;/<span class="hljs-title">li</span>&gt;</span></div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="34"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line"><span class="hljs-class">          @<span class="hljs-title">foreach</span>($<span class="hljs-title">category</span> <span class="hljs-title">as</span> $<span class="hljs-title">v</span>)</span></div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="35"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line"><span class="hljs-class">            @<span class="hljs-title">if</span>(<span class="hljs-title">isset</span>($<span class="hljs-title">v</span>['<span class="hljs-title">sub</span>']))</span></div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="36"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line"><span class="hljs-class">              &lt;<span class="hljs-title">li</span> <span class="hljs-title">class</span>="<span class="hljs-title">nav</span>-<span class="hljs-title">item</span> <span class="hljs-title">dropdown</span>"&gt;</span></div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="37"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line"><span class="hljs-class">                &lt;<span class="hljs-title">a</span> <span class="hljs-title">class</span>="<span class="hljs-title">nav</span>-<span class="hljs-title">link</span> <span class="hljs-title">dropdown</span>-<span class="hljs-title">toggle</span>" <span class="hljs-title">href</span>="#" <span class="hljs-title">id</span>="<span class="hljs-title">navbarDropdown</span>" <span class="hljs-title">role</span>="<span class="hljs-title">button</span>" <span class="hljs-title">data</span>-<span class="hljs-title">toggle</span>="<span class="hljs-title">dropdown</span>" <span class="hljs-title">aria</span>-<span class="hljs-title">haspopup</span>="<span class="hljs-title">true</span>" <span class="hljs-title">aria</span>-<span class="hljs-title">expanded</span>="<span class="hljs-title">false</span>"&gt;</span></div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="38"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line"><span class="hljs-class">                  </span>{{<span class="hljs-variable">$v</span>[<span class="hljs-string">'name'</span>]}}</div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="39"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line">                &lt;/a&gt;</div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="40"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line">                &lt;div <span class="hljs-class"><span class="hljs-class"><span class="hljs-keyword">class</span>="<span class="hljs-title">dropdown</span>-<span class="hljs-title">menu</span>" <span class="hljs-title">aria</span>-<span class="hljs-title">labelledby</span>="<span class="hljs-title">navbarDropdown</span>"&gt;</span></span></div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="41"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line"><span class="hljs-class">                  @<span class="hljs-title">foreach</span>($<span class="hljs-title">v</span>['<span class="hljs-title">sub</span>'] <span class="hljs-title">as</span> $<span class="hljs-title">val</span>)</span></div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="42"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line"><span class="hljs-class">                    &lt;<span class="hljs-title">a</span> <span class="hljs-title">class</span>="<span class="hljs-title">dropdown</span>-<span class="hljs-title">item</span>" <span class="hljs-title">href</span>="</span>{{<span class="hljs-title function_ invoke__">url</span>(<span class="hljs-string">'lists'</span>, [<span class="hljs-string">'id'</span> =&gt; <span class="hljs-variable">$val</span>[<span class="hljs-string">'id'</span>]] )}}<span class="hljs-string"><span class="hljs-string">"&gt;{<span class="hljs-subst">{$val['name']}</span>}&lt;/a&gt;</span></span></div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="43"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line"><span class="hljs-string">                  @endforeach</span></div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="44"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line"><span class="hljs-string">                &lt;/div&gt;</span></div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="45"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line"><span class="hljs-string">              &lt;/li&gt;</span></div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="46"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line"><span class="hljs-string">            @else</span></div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="47"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line"><span class="hljs-string">              &lt;li class="</span>nav-item<span class="hljs-string"><span class="hljs-string">"&gt;</span></span></div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="48"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line"><span class="hljs-string">                &lt;a class="</span>nav-link<span class="hljs-string">" href="</span>{{<span class="hljs-title function_ invoke__">url</span>(<span class="hljs-string">'lists'</span>, [<span class="hljs-string">'id'</span> =&gt; <span class="hljs-variable">$v</span>[<span class="hljs-string">'id'</span>]] )}}<span class="hljs-string"><span class="hljs-string">"&gt;{<span class="hljs-subst">{$v['name']}</span>}&lt;/a&gt;</span></span></div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="49"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line"><span class="hljs-string">              &lt;/li&gt;</span></div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="50"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line"><span class="hljs-string">            @endif</span></div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="51"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line"><span class="hljs-string">          @endforeach</span></div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="52"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line"><span class="hljs-string">        &lt;/ul&gt;</span></div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="53"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line"><span class="hljs-string">      &lt;/div&gt;</span></div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="54"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line"><span class="hljs-string">    &lt;/div&gt;</span></div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="55"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line"><span class="hljs-string">  &lt;/nav&gt;</span></div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="56"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line"><span class="hljs-string">&lt;/div&gt;</span></div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="57"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line"><span class="hljs-string">&lt;!-- 登录表单 ---&gt;</span></div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="58"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line"><span class="hljs-string">&lt;div class="</span>modal fade<span class="hljs-string">" id="</span>loginModal<span class="hljs-string">" tabindex="</span>-<span class="hljs-number">1</span><span class="hljs-string">" role="</span>dialog<span class="hljs-string">" aria-labelledby="</span>exampleModalLabel<span class="hljs-string">" aria-hidden="</span><span class="hljs-literal">true</span><span class="hljs-string"><span class="hljs-string">"&gt;</span></span></div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="59"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line"><span class="hljs-string">  &lt;div class="</span>modal-dialog<span class="hljs-string"><span class="hljs-string">"&gt;</span></span></div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="60"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line"><span class="hljs-string">    &lt;div class="</span>modal-content<span class="hljs-string"><span class="hljs-string">"&gt;</span></span></div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="61"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line"><span class="hljs-string">      &lt;div class="</span>modal-header<span class="hljs-string"><span class="hljs-string">"&gt;</span></span></div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="62"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line"><span class="hljs-string">        &lt;h5 class="</span>modal-title<span class="hljs-string"><span class="hljs-string">"&gt;登录&lt;/h5&gt;</span></span></div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="63"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line"><span class="hljs-string">        &lt;button type="</span>button<span class="hljs-string">" class="</span>close<span class="hljs-string">" data-dismiss="</span>modal<span class="hljs-string">" aria-label="</span>Close<span class="hljs-string"><span class="hljs-string">"&gt;</span></span></div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="64"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line"><span class="hljs-string">          &lt;span aria-hidden="</span><span class="hljs-literal">true</span><span class="hljs-string"><span class="hljs-string">"&gt;&amp;times;&lt;/span&gt;</span></span></div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="65"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line"><span class="hljs-string">        &lt;/button&gt;</span></div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="66"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line"><span class="hljs-string">      &lt;/div&gt;</span></div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="67"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line"><span class="hljs-string">      &lt;div class="</span>modal-body<span class="hljs-string"><span class="hljs-string">"&gt;</span></span></div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="68"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line"><span class="hljs-string">        &lt;div class="</span>form-group<span class="hljs-string"><span class="hljs-string">"&gt;</span></span></div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="69"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line"><span class="hljs-string">          &lt;label for="</span>username<span class="hljs-string"><span class="hljs-string">"&gt;用户名&lt;/label&gt;</span></span></div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="70"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line"><span class="hljs-string">          &lt;input type="</span>text<span class="hljs-string">" name="</span>name<span class="hljs-string">" class="</span>form-control<span class="hljs-string">" id="</span>username<span class="hljs-string"><span class="hljs-string">"&gt;</span></span></div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="71"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line"><span class="hljs-string">        &lt;/div&gt;</span></div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="72"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line"><span class="hljs-string">        &lt;div class="</span>form-group<span class="hljs-string"><span class="hljs-string">"&gt;</span></span></div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="73"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line"><span class="hljs-string">          &lt;label for="</span>password<span class="hljs-string"><span class="hljs-string">"&gt;密码&lt;/label&gt;</span></span></div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="74"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line"><span class="hljs-string">          &lt;input type="</span>password<span class="hljs-string">" name="</span>password<span class="hljs-string">" class="</span>form-control<span class="hljs-string">" id="</span>password<span class="hljs-string"><span class="hljs-string">"&gt;</span></span></div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="75"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line"><span class="hljs-string">        &lt;/div&gt;</span></div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="76"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line"><span class="hljs-string">      &lt;/div&gt;</span></div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="77"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line"><span class="hljs-string">      &lt;div class="</span>modal-footer<span class="hljs-string"><span class="hljs-string">"&gt;</span></span></div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="78"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line"><span class="hljs-string">        &lt;button type="</span>button<span class="hljs-string">" class="</span>btn btn-secondary<span class="hljs-string">" data-dismiss="</span>modal<span class="hljs-string"><span class="hljs-string">"&gt;关闭&lt;/button&gt;</span></span></div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="79"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line"><span class="hljs-string">        &lt;button type="</span>submit<span class="hljs-string">" class="</span>btn btn-primary<span class="hljs-string">" id="</span>login<span class="hljs-string"><span class="hljs-string">"&gt;登录</span></span></div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="80"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line"><span class="hljs-string">        &lt;/button&gt;</span></div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="81"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line"><span class="hljs-string">      &lt;/div&gt;</span></div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="82"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line"><span class="hljs-string">    &lt;/div&gt;</span></div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="83"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line"><span class="hljs-string">  &lt;/div&gt;</span></div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="84"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line"><span class="hljs-string">&lt;/div&gt;</span></div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="85"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line"><span class="hljs-string">&lt;!-- 注册表单 ---&gt;</span></div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="86"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line"><span class="hljs-string">&lt;div class="</span>modal fade<span class="hljs-string">" id="</span>registerModal<span class="hljs-string">" tabindex="</span>-<span class="hljs-number">1</span><span class="hljs-string">" role="</span>dialog<span class="hljs-string">" aria-labelledby="</span>exampleModalLabel<span class="hljs-string">" aria-hidden="</span><span class="hljs-literal">true</span><span class="hljs-string"><span class="hljs-string">"&gt;</span></span></div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="87"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line"><span class="hljs-string">  &lt;div class="</span>modal-dialog<span class="hljs-string"><span class="hljs-string">"&gt;</span></span></div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="88"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line"><span class="hljs-string">    &lt;div class="</span>modal-content<span class="hljs-string"><span class="hljs-string">"&gt;</span></span></div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="89"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line"><span class="hljs-string">      &lt;div class="</span>modal-header<span class="hljs-string"><span class="hljs-string">"&gt;</span></span></div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="90"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line"><span class="hljs-string">        &lt;h5 class="</span>modal-title<span class="hljs-string"><span class="hljs-string">"&gt;注册&lt;/h5&gt;</span></span></div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="91"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line"><span class="hljs-string">        &lt;button type="</span>button<span class="hljs-string">" class="</span>close<span class="hljs-string">" data-dismiss="</span>modal<span class="hljs-string">" aria-label="</span>Close<span class="hljs-string"><span class="hljs-string">"&gt;</span></span></div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="92"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line"><span class="hljs-string">          &lt;span aria-hidden="</span><span class="hljs-literal">true</span><span class="hljs-string"><span class="hljs-string">"&gt;&amp;times;&lt;/span&gt;</span></span></div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="93"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line"><span class="hljs-string">        &lt;/button&gt;</span></div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="94"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line"><span class="hljs-string">      &lt;/div&gt;</span></div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="95"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line"><span class="hljs-string">      &lt;div class="</span>modal-body<span class="hljs-string"><span class="hljs-string">"&gt;</span></span></div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="96"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line"><span class="hljs-string">        &lt;div class="</span>form-group<span class="hljs-string"><span class="hljs-string">"&gt;</span></span></div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="97"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line"><span class="hljs-string">          &lt;label for="</span>username1<span class="hljs-string"><span class="hljs-string">"&gt;用户名&lt;/label&gt;</span></span></div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="98"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line"><span class="hljs-string">          &lt;input type="</span>text<span class="hljs-string">" name="</span>name<span class="hljs-string">" class="</span>form-control<span class="hljs-string">" id="</span>username1<span class="hljs-string"><span class="hljs-string">"&gt;</span></span></div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="99"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line"><span class="hljs-string">        &lt;/div&gt;</span></div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="100"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line"><span class="hljs-string">        &lt;div class="</span>form-group<span class="hljs-string"><span class="hljs-string">"&gt;</span></span></div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="101"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line"><span class="hljs-string">          &lt;label for="</span>email<span class="hljs-string"><span class="hljs-string">"&gt;邮箱&lt;/label&gt;</span></span></div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="102"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line"><span class="hljs-string">          &lt;input type="</span>email<span class="hljs-string">" name="</span>email<span class="hljs-string">" class="</span>form-control<span class="hljs-string">" id="</span>email<span class="hljs-string"><span class="hljs-string">"&gt;</span></span></div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="103"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line"><span class="hljs-string">        &lt;/div&gt;</span></div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="104"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line"><span class="hljs-string">        &lt;div class="</span>form-group<span class="hljs-string"><span class="hljs-string">"&gt;</span></span></div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="105"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line"><span class="hljs-string">          &lt;label for="</span>password1<span class="hljs-string"><span class="hljs-string">"&gt;密码&lt;/label&gt;</span></span></div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="106"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line"><span class="hljs-string">          &lt;input type="</span>password<span class="hljs-string">" name="</span>password<span class="hljs-string">" class="</span>form-control<span class="hljs-string">" id="</span>password1<span class="hljs-string"><span class="hljs-string">"&gt;</span></span></div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="107"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line"><span class="hljs-string">        &lt;/div&gt;</span></div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="108"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line"><span class="hljs-string">        &lt;div class="</span>form-group<span class="hljs-string"><span class="hljs-string">"&gt;</span></span></div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="109"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line"><span class="hljs-string">          &lt;label for="</span>confirm<span class="hljs-string"><span class="hljs-string">"&gt;确认密码&lt;/label&gt;</span></span></div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="110"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line"><span class="hljs-string">          &lt;input type="</span>password<span class="hljs-string">" class="</span>form-control<span class="hljs-string">" id="</span>confirm<span class="hljs-string"><span class="hljs-string">"&gt;</span></span></div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="111"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line"><span class="hljs-string">        &lt;/div&gt;</span></div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="112"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line"><span class="hljs-string">      &lt;/div&gt;</span></div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="113"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line"><span class="hljs-string">      &lt;div class="</span>modal-footer<span class="hljs-string"><span class="hljs-string">"&gt;</span></span></div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="114"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line"><span class="hljs-string">        {{csrf_field()}}</span></div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="115"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line"><span class="hljs-string">        &lt;button type="</span>button<span class="hljs-string">" class="</span>btn btn-secondary<span class="hljs-string">" data-dismiss="</span>modal<span class="hljs-string"><span class="hljs-string">"&gt;关闭&lt;/button&gt;</span></span></div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="116"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line"><span class="hljs-string">        &lt;button type="</span>submit<span class="hljs-string">" class="</span>btn btn-primary<span class="hljs-string">" id="</span>register<span class="hljs-string"><span class="hljs-string">"&gt;立即注册&lt;/button&gt;</span></span></div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="117"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line"><span class="hljs-string">      &lt;/div&gt;</span></div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="118"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line"><span class="hljs-string">    &lt;/div&gt;</span></div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="119"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line"><span class="hljs-string">  &lt;/div&gt;</span></div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="120"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line"><span class="hljs-string">&lt;/div&gt;</span></div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="121"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line"><span class="hljs-string">&lt;script&gt;</span></div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="122"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line"><span class="hljs-string">  $("</span><span class="hljs-comment">#login").bind("click",function(){</span></div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="123"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line">    <span class="hljs-keyword">var</span> data = {</div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="124"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line">      <span class="hljs-string">'name'</span>   : $(<span class="hljs-string">"#username"</span>).<span class="hljs-title function_ invoke__">val</span>(),</div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="125"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line">      <span class="hljs-string">'password'</span> : $(<span class="hljs-string">"#password"</span>).<span class="hljs-title function_ invoke__">val</span>(),</div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="126"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line">      <span class="hljs-string">'_token'</span>   : <span class="hljs-string">"{{ csrf_token() }}"</span></div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="127"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line">    };</div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="128"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line">    $.<span class="hljs-title function_ invoke__">post</span>(<span class="hljs-string">"{{ url('login') }}"</span>, data, function(result){</div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="129"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line">      <span class="hljs-keyword">if</span> (result.status == <span class="hljs-number">1</span>) {</div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="130"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line">        <span class="hljs-title function_ invoke__">alert</span>(result.msg);</div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="131"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line">        window.location.<span class="hljs-title function_ invoke__">reload</span>();</div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="132"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line">      } <span class="hljs-keyword">else</span> {</div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="133"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line">        <span class="hljs-title function_ invoke__">alert</span>(result.msg);</div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="134"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line">        <span class="hljs-keyword">return</span>;</div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="135"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line">      }</div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="136"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line">    });</div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="137"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line">  });</div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="138"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line">  $(<span class="hljs-string">"#register"</span>).<span class="hljs-title function_ invoke__">bind</span>(<span class="hljs-string">"click"</span>,function(){</div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="139"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line">    <span class="hljs-keyword">var</span> data = {</div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="140"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line">      <span class="hljs-string">'name'</span>           : $(<span class="hljs-string">"#username1"</span>).<span class="hljs-title function_ invoke__">val</span>(),</div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="141"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line">      <span class="hljs-string">'email'</span>          : $(<span class="hljs-string">"#email"</span>).<span class="hljs-title function_ invoke__">val</span>(),</div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="142"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line">      <span class="hljs-string">'password'</span>         : $(<span class="hljs-string">"#password1"</span>).<span class="hljs-title function_ invoke__">val</span>(),</div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="143"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line">      <span class="hljs-string">' password_confirmation'</span> : $(<span class="hljs-string">"#confirm"</span>).<span class="hljs-title function_ invoke__">val</span>(),</div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="144"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line">      <span class="hljs-string">'_token'</span>         : <span class="hljs-string">"{{ csrf_token() }}"</span></div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="145"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line">    };</div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="146"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line">    $.<span class="hljs-title function_ invoke__">post</span>(<span class="hljs-string">"{{ url('register') }}"</span>, data, function(result){</div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="147"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line">      <span class="hljs-keyword">if</span> (result.status == <span class="hljs-number">1</span>) {</div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="148"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line">        <span class="hljs-title function_ invoke__">alert</span>(result.msg);</div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="149"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line">        $(<span class="hljs-string">'#registerModal'</span>).<span class="hljs-title function_ invoke__">modal</span>(<span class="hljs-string">'hide'</span>);</div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="150"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line">        location.<span class="hljs-title function_ invoke__">reload</span>();</div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="151"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line">      } <span class="hljs-keyword">else</span> {</div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="152"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line">        <span class="hljs-title function_ invoke__">alert</span>(result.msg);</div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="153"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line">        <span class="hljs-keyword">return</span>;</div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="154"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line">      }</div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="155"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line">    });</div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="156"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line">  });</div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="157"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line">&lt;/script&gt;</div></div></li></ol></code><div class="hljs-button {2}" data-title="复制" onclick="hljs.copyCode(event)"></div></pre> 
<p>（2）创建<strong>User</strong>控制器，具体代码如下：</p> 
<pre data-index="136" class="set-code-show" name="code"><code class="language-php hljs">php artisan make:controller UserController</code><div class="hljs-button {2}" data-title="复制" onclick="hljs.copyCode(event)"></div></pre> 
<p>(3)在User控制器中添加方法，具体代码如下：</p> 
<pre data-index="137" class="set-code-show" name="code"><code class="language-php hljs"><ol class="hljs-ln" style="width:100%"><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="1"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line"><span class="hljs-meta">&lt;?php</span></div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="2"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line"> </div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="3"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line"><span class="hljs-keyword">namespace</span> <span class="hljs-title class_">App</span>\<span class="hljs-title class_">Http</span>\<span class="hljs-title class_">Controllers</span>;</div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="4"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line"> </div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="5"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line"><span class="hljs-keyword">use</span> <span class="hljs-title">Illuminate</span>\<span class="hljs-title">Http</span>\<span class="hljs-title">Request</span>;</div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="6"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line"><span class="hljs-keyword">use</span> <span class="hljs-title">Illuminate</span>\<span class="hljs-title">Support</span>\<span class="hljs-title">Facades</span>\<span class="hljs-title">Validator</span>;</div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="7"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line"><span class="hljs-keyword">use</span> <span class="hljs-title">App</span>\<span class="hljs-title">User</span>;</div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="8"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line"><span class="hljs-keyword">use</span> <span class="hljs-title">Illuminate</span>\<span class="hljs-title">Support</span>\<span class="hljs-title">Facades</span>\<span class="hljs-title">Session</span>;</div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="9"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line"> </div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="10"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line"> </div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="11"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line"><span class="hljs-class"><span class="hljs-keyword">class</span> <span class="hljs-title">UserController</span> <span class="hljs-keyword">extends</span> <span class="hljs-title">Controller</span></span></div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="12"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line">{</div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="13"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line">    <span class="hljs-keyword">public</span> <span class="hljs-function"><span class="hljs-keyword">function</span> <span class="hljs-title">register</span>(<span class="hljs-params">Request <span class="hljs-variable">$request</span></span>)</span></div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="14"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line">    {</div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="15"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line">        <span class="hljs-variable">$rule</span> = [</div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="16"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line">            <span class="hljs-string">'name'</span> =&gt; <span class="hljs-string">'required|unique:users'</span>,</div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="17"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line">            <span class="hljs-string">'email'</span> =&gt; <span class="hljs-string">'required|email'</span>,</div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="18"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line">            <span class="hljs-string">'password'</span> =&gt; <span class="hljs-string">'required|min:6'</span>,</div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="19"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line">            <span class="hljs-string">'password_confirmation'</span> =&gt; <span class="hljs-string">'required'</span></div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="20"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line">        ];</div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="21"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line">        <span class="hljs-variable">$message</span> = [</div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="22"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line">            <span class="hljs-string">'name.require'</span> =&gt; <span class="hljs-string">'用户名不能为空'</span>,</div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="23"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line">            <span class="hljs-string">'name.unique'</span> =&gt; <span class="hljs-string">'用户名不能重复'</span>,</div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="24"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line">            <span class="hljs-string">'email.require'</span> =&gt; <span class="hljs-string">'邮箱不能为空'</span>,</div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="25"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line">            <span class="hljs-string">'email.email'</span> =&gt; <span class="hljs-string">'邮箱格式不符合规范'</span>,</div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="26"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line">            <span class="hljs-string">'password.require'</span> =&gt; <span class="hljs-string">'密码不能为空'</span>,</div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="27"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line">            <span class="hljs-string">'password.min'</span> =&gt; <span class="hljs-string">'密码最少为6位'</span>,</div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="28"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line">            <span class="hljs-string">'password.confirmed'</span> =&gt; <span class="hljs-string">'密码和确认密码不一致'</span></div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="29"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line">        ];</div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="30"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line">        <span class="hljs-variable">$validator</span> = <span class="hljs-title class_">Validator</span>::<span class="hljs-title function_ invoke__">make</span>(<span class="hljs-variable">$request</span>-&gt;<span class="hljs-title function_ invoke__">all</span>(), <span class="hljs-variable">$rule</span>, <span class="hljs-variable">$message</span>);</div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="31"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line">        <span class="hljs-keyword">if</span> (<span class="hljs-variable">$validator</span>-&gt;<span class="hljs-title function_ invoke__">fails</span>()) {</div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="32"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line">            <span class="hljs-keyword">foreach</span> (<span class="hljs-variable">$validator</span>-&gt;<span class="hljs-title function_ invoke__">getMessageBag</span>()-&gt;<span class="hljs-title function_ invoke__">toArray</span>() <span class="hljs-keyword">as</span> <span class="hljs-variable">$v</span>) {</div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="33"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line">                <span class="hljs-variable">$msg</span> = <span class="hljs-variable">$v</span>[<span class="hljs-number">0</span>];</div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="34"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line">            }</div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="35"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line">            <span class="hljs-keyword">return</span> <span class="hljs-title function_ invoke__">response</span>()-&gt;<span class="hljs-title function_ invoke__">json</span>([<span class="hljs-string">'status'</span> =&gt; <span class="hljs-string">'2'</span>, <span class="hljs-string">'msg'</span> =&gt; <span class="hljs-variable">$msg</span>]);</div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="36"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line">        }</div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="37"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line">        <span class="hljs-variable">$re</span> = <span class="hljs-title class_">User</span>::<span class="hljs-title function_ invoke__">create</span>(<span class="hljs-variable">$request</span>-&gt;<span class="hljs-title function_ invoke__">all</span>());</div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="38"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line">        <span class="hljs-keyword">if</span> (<span class="hljs-variable">$re</span>) {</div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="39"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line">            <span class="hljs-title class_">Session</span>::<span class="hljs-title function_ invoke__">put</span>(<span class="hljs-string">'users'</span>, [<span class="hljs-string">'id'</span> =&gt; <span class="hljs-variable">$re</span>-&gt;id, <span class="hljs-string">'name'</span> =&gt; <span class="hljs-variable">$re</span>-&gt;name]); <span class="hljs-comment">// 注册成功后保存登录状态</span></div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="40"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line">            <span class="hljs-keyword">return</span> <span class="hljs-title function_ invoke__">response</span>()-&gt;<span class="hljs-title function_ invoke__">json</span>([<span class="hljs-string">'status'</span> =&gt; <span class="hljs-string">'1'</span>, <span class="hljs-string">'msg'</span> =&gt; <span class="hljs-string">'注册成功'</span>]);</div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="41"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line">        } <span class="hljs-keyword">else</span> {</div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="42"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line">            <span class="hljs-keyword">return</span> <span class="hljs-title function_ invoke__">response</span>()-&gt;<span class="hljs-title function_ invoke__">json</span>([<span class="hljs-string">'status'</span> =&gt; <span class="hljs-string">'2'</span>, <span class="hljs-string">'msg'</span> =&gt; <span class="hljs-string">'注册失败'</span>]);</div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="43"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line">        }</div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="44"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line"> </div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="45"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line">    }</div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="46"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line"> </div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="47"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line">    <span class="hljs-keyword">public</span> <span class="hljs-function"><span class="hljs-keyword">function</span> <span class="hljs-title">login</span>(<span class="hljs-params">Request <span class="hljs-variable">$request</span></span>)</span></div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="48"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line">    {</div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="49"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line">        <span class="hljs-variable">$rule</span> = [</div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="50"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line">            <span class="hljs-string">'name'</span> =&gt; <span class="hljs-string">'required|bail'</span>,</div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="51"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line">            <span class="hljs-string">'password'</span> =&gt; <span class="hljs-string">'required|min:6'</span></div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="52"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line">        ];</div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="53"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line">        <span class="hljs-variable">$message</span> = [</div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="54"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line">            <span class="hljs-string">'name.required'</span> =&gt; <span class="hljs-string">'用户名不能为空'</span>,</div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="55"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line">            <span class="hljs-string">'password.required'</span> =&gt; <span class="hljs-string">'密码不能为空'</span>,</div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="56"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line">            <span class="hljs-string">'password.min'</span> =&gt; <span class="hljs-string">'密码最少为6位'</span></div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="57"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line">        ];</div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="58"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line">        <span class="hljs-variable">$validator</span> = <span class="hljs-title class_">Validator</span>::<span class="hljs-title function_ invoke__">make</span>(<span class="hljs-variable">$request</span>-&gt;<span class="hljs-title function_ invoke__">all</span>(), <span class="hljs-variable">$rule</span>, <span class="hljs-variable">$message</span>);</div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="59"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line">        <span class="hljs-keyword">if</span> (<span class="hljs-variable">$validator</span>-&gt;<span class="hljs-title function_ invoke__">fails</span>()) {</div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="60"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line">            <span class="hljs-keyword">foreach</span> (<span class="hljs-variable">$validator</span>-&gt;<span class="hljs-title function_ invoke__">getMessageBag</span>()-&gt;<span class="hljs-title function_ invoke__">toArray</span>() <span class="hljs-keyword">as</span> <span class="hljs-variable">$v</span>) {</div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="61"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line">                <span class="hljs-variable">$msg</span> = <span class="hljs-variable">$v</span>[<span class="hljs-number">0</span>];</div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="62"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line">            }</div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="63"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line">            <span class="hljs-keyword">return</span> <span class="hljs-title function_ invoke__">response</span>()-&gt;<span class="hljs-title function_ invoke__">json</span>([<span class="hljs-string">'status'</span>=&gt;<span class="hljs-string">'2'</span>, <span class="hljs-string">'msg'</span>=&gt;<span class="hljs-variable">$msg</span>]);</div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="64"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line">        }</div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="65"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line">        <span class="hljs-variable">$name</span> = <span class="hljs-variable">$request</span>-&gt;<span class="hljs-title function_ invoke__">get</span>(<span class="hljs-string">'name'</span>);</div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="66"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line">        <span class="hljs-variable">$password</span> = <span class="hljs-variable">$request</span>-&gt;<span class="hljs-title function_ invoke__">get</span>(<span class="hljs-string">'password'</span>);</div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="67"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line">        <span class="hljs-variable">$theUser</span> = <span class="hljs-title class_">User</span>::<span class="hljs-title function_ invoke__">where</span>(<span class="hljs-string">'name'</span>, <span class="hljs-variable">$name</span>)-&gt;<span class="hljs-title function_ invoke__">first</span>();</div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="68"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line">        <span class="hljs-keyword">if</span> (<span class="hljs-variable">$theUser</span>) {</div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="69"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line">            <span class="hljs-keyword">if</span> (<span class="hljs-variable">$password</span> == <span class="hljs-variable">$theUser</span>-&gt;password) {</div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="70"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line">                <span class="hljs-title class_">Session</span>::<span class="hljs-title function_ invoke__">put</span>(<span class="hljs-string">'users'</span>, [<span class="hljs-string">'id'</span> =&gt; <span class="hljs-variable">$theUser</span>-&gt;id,<span class="hljs-string">'name'</span> =&gt; <span class="hljs-variable">$name</span>]);</div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="71"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line">                <span class="hljs-keyword">return</span> <span class="hljs-title function_ invoke__">response</span>()-&gt;<span class="hljs-title function_ invoke__">json</span>([<span class="hljs-string">'status'</span> =&gt; <span class="hljs-string">'1'</span>, <span class="hljs-string">'msg'</span> =&gt; <span class="hljs-string">'登录成功'</span>]);</div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="72"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line">            } <span class="hljs-keyword">else</span> {</div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="73"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line">                <span class="hljs-keyword">return</span> <span class="hljs-title function_ invoke__">response</span>()-&gt;<span class="hljs-title function_ invoke__">json</span>([<span class="hljs-string">'status'</span> =&gt; <span class="hljs-string">'2'</span>, <span class="hljs-string">'msg'</span> =&gt; <span class="hljs-string">'密码错误'</span>]);</div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="74"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line">            }</div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="75"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line">        } <span class="hljs-keyword">else</span> {</div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="76"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line">            <span class="hljs-keyword">return</span> <span class="hljs-title function_ invoke__">response</span>()-&gt;<span class="hljs-title function_ invoke__">json</span>([<span class="hljs-string">'status'</span> =&gt; <span class="hljs-string">'2'</span>, <span class="hljs-string">'msg'</span> =&gt; <span class="hljs-string">'用户不存在'</span>]);</div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="77"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line">        }</div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="78"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line">    }</div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="79"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line"> </div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="80"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line">    <span class="hljs-keyword">public</span> <span class="hljs-function"><span class="hljs-keyword">function</span> <span class="hljs-title">logout</span>(<span class="hljs-params"></span>)</span></div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="81"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line">    {</div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="82"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line">        <span class="hljs-keyword">if</span> (<span class="hljs-title function_ invoke__">request</span>()-&gt;<span class="hljs-title function_ invoke__">session</span>()-&gt;<span class="hljs-title function_ invoke__">has</span>(<span class="hljs-string">'users'</span>)) {</div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="83"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line">            <span class="hljs-title function_ invoke__">request</span>()-&gt;<span class="hljs-title function_ invoke__">session</span>()-&gt;<span class="hljs-title function_ invoke__">pull</span>(<span class="hljs-string">'users'</span>, <span class="hljs-title function_ invoke__">session</span>(<span class="hljs-string">'users'</span>));</div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="84"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line">        }</div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="85"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line">        <span class="hljs-keyword">return</span> <span class="hljs-title function_ invoke__">redirect</span>(<span class="hljs-string">'/'</span>);</div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="86"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line">    }</div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="87"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line"> </div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="88"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line">}</div></div></li></ol></code><div class="hljs-button {2}" data-title="复制" onclick="hljs.copyCode(event)"></div></pre> 
<h3 id="%E5%86%85%E5%AE%B9%E5%88%97%E8%A1%A8%E9%A1%B5"><a name="t41"></a>内容列表页</h3> 
<h4 id="%E4%B8%80%E3%80%81%E5%86%85%E5%AE%B9%E5%88%97%E8%A1%A8"><a name="t42"></a>一、内容列表</h4> 
<p>（1）在<strong>resources\views</strong>目录下创建<strong>lists.blade.php</strong>，具体代码如下：</p> 
<pre data-index="138" class="set-code-show" name="code"><code class="language-php hljs"><ol class="hljs-ln" style="width:1144px"><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="1"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line">&lt;!DOCTYPE html&gt;</div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="2"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line">&lt;html&gt;</div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="3"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line">&lt;head&gt;</div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="4"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line">  @<span class="hljs-keyword">include</span>(<span class="hljs-string">'public/static'</span>)</div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="5"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line">  &lt;title&gt;列表页&lt;/title&gt;</div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="6"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line">&lt;/head&gt;</div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="7"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line">&lt;body&gt;</div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="8"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line">@<span class="hljs-keyword">include</span>(<span class="hljs-string">'public/header'</span>)</div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="9"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line">&lt;div <span class="hljs-class"><span class="hljs-class"><span class="hljs-keyword">class</span>="<span class="hljs-title">main</span>"&gt;</span></span></div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="10"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line"><span class="hljs-class">  &lt;<span class="hljs-title">div</span> <span class="hljs-title">class</span>="<span class="hljs-title">main</span>-<span class="hljs-title">crumb</span>"&gt;</span></div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="11"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line"><span class="hljs-class">    &lt;<span class="hljs-title">div</span> <span class="hljs-title">class</span>="<span class="hljs-title">container</span>"&gt;</span></div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="12"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line"><span class="hljs-class">      &lt;!-- 面包屑导航 --&gt;</span></div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="13"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line"><span class="hljs-class">      &lt;<span class="hljs-title">nav</span> <span class="hljs-title">aria</span>-<span class="hljs-title">label</span>="<span class="hljs-title">breadcrumb</span>"&gt;</span></div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="14"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line"><span class="hljs-class">        </span>{!! <span class="hljs-title class_">Breadcrumbs</span>::<span class="hljs-title function_ invoke__">render</span>(<span class="hljs-string">'category'</span>, <span class="hljs-variable">$id</span>); !!}</div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="15"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line">      &lt;/nav&gt;</div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="16"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line">    &lt;/div&gt;</div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="17"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line">  &lt;/div&gt;</div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="18"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line">  &lt;div <span class="hljs-class"><span class="hljs-class"><span class="hljs-keyword">class</span>="<span class="hljs-title">container</span>"&gt;</span></span></div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="19"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line"><span class="hljs-class">    &lt;<span class="hljs-title">div</span> <span class="hljs-title">class</span>="<span class="hljs-title">row</span>"&gt;</span></div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="20"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line"><span class="hljs-class">      &lt;<span class="hljs-title">div</span> <span class="hljs-title">class</span>="<span class="hljs-title">col</span>-<span class="hljs-title">md</span>-9"&gt;</span></div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="21"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line"><span class="hljs-class">        &lt;<span class="hljs-title">div</span> <span class="hljs-title">class</span>="<span class="hljs-title">row</span>"&gt;</span></div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="22"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line"><span class="hljs-class">          &lt;!-- 内容列表 --&gt;</span></div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="23"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line"><span class="hljs-class">          @<span class="hljs-title">foreach</span>($<span class="hljs-title">content</span> <span class="hljs-title">as</span> $<span class="hljs-title">con</span>)</span></div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="24"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line"><span class="hljs-class">          &lt;<span class="hljs-title">div</span> <span class="hljs-title">class</span>="<span class="hljs-title">col</span>-<span class="hljs-title">md</span>-6 <span class="hljs-title">mb</span>-4"&gt;</span></div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="25"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line"><span class="hljs-class">            &lt;<span class="hljs-title">div</span> <span class="hljs-title">class</span>="<span class="hljs-title">card</span> <span class="hljs-title">main</span>-<span class="hljs-title">card</span>"&gt;</span></div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="26"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line"><span class="hljs-class">              &lt;<span class="hljs-title">div</span> <span class="hljs-title">class</span>="<span class="hljs-title">main</span>-<span class="hljs-title">card</span>-<span class="hljs-title">pic</span>"&gt;</span></div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="27"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line"><span class="hljs-class">                &lt;<span class="hljs-title">a</span> <span class="hljs-title">href</span>="</span>{{ <span class="hljs-title function_ invoke__">url</span>(<span class="hljs-string">'detail'</span>, [<span class="hljs-string">'id'</span> =&gt; <span class="hljs-variable">$con</span>-&gt;id ])}}<span class="hljs-string"><span class="hljs-string">"&gt;</span></span></div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="28"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line"><span class="hljs-string">                  &lt;img class="</span>img-fluid<span class="hljs-string">" src="</span>@<span class="hljs-keyword">if</span>(<span class="hljs-variable">$con</span>-&gt;image)/<span class="hljs-built_in">static</span>/upload/{{<span class="hljs-variable">$con</span>-&gt;image}}@<span class="hljs-keyword">else</span> {{<span class="hljs-title function_ invoke__">asset</span>(<span class="hljs-string">'admin'</span>)}}/img/noimg.png @<span class="hljs-keyword">endif</span><span class="hljs-string"><span class="hljs-string">"&gt;</span></span></div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="29"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line"><span class="hljs-string">                  &lt;span&gt;&lt;i class="</span>fa fa-search<span class="hljs-string"><span class="hljs-string">"&gt;&lt;/i&gt;&lt;/span&gt;</span></span></div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="30"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line"><span class="hljs-string">                &lt;/a&gt;</span></div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="31"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line"><span class="hljs-string">              &lt;/div&gt;</span></div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="32"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line"><span class="hljs-string">              &lt;div class="</span>card-body<span class="hljs-string"><span class="hljs-string">"&gt;</span></span></div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="33"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line"><span class="hljs-string">                &lt;div class="</span>main-card-info<span class="hljs-string"><span class="hljs-string">"&gt;</span></span></div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="34"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line"><span class="hljs-string">                  &lt;span&gt;&lt;i class="</span>fa fa-calendar<span class="hljs-string"><span class="hljs-string">"&gt;&lt;/i&gt;{{ date('Y-m-d', strtotime(<span class="hljs-subst">$con</span>-&gt;created_at)) }}&lt;/span&gt;</span></span></div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="35"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line"><span class="hljs-string">                  &lt;span&gt;&lt;i class="</span>fa fa-comments<span class="hljs-string"><span class="hljs-string">"&gt;&lt;/i&gt;{<span class="hljs-subst">{$con-&gt;comments-&gt;count()}</span>}&lt;/span&gt;</span></span></div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="36"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line"><span class="hljs-string">                &lt;/div&gt;</span></div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="37"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line"><span class="hljs-string">                &lt;h3&gt;&lt;a href="</span>{{ <span class="hljs-title function_ invoke__">url</span>(<span class="hljs-string">'detail'</span>, [<span class="hljs-string">'id'</span> =&gt; <span class="hljs-variable">$con</span>-&gt;id ])}}<span class="hljs-string"><span class="hljs-string">"&gt;{<span class="hljs-subst">{$con-&gt;title}</span>}&lt;/a&gt;&lt;/h3&gt;</span></span></div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="38"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line"><span class="hljs-string">                &lt;div class="</span>main-card-desc<span class="hljs-string"><span class="hljs-string">"&gt;{{str_limit(strip_tags(<span class="hljs-subst">$con</span>-&gt;content),100)}}&lt;/div&gt;</span></span></div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="39"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line"><span class="hljs-string">              &lt;/div&gt;</span></div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="40"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line"><span class="hljs-string">              &lt;a href="</span>{{ <span class="hljs-title function_ invoke__">url</span>(<span class="hljs-string">'detail'</span>, [<span class="hljs-string">'id'</span> =&gt; <span class="hljs-variable">$con</span>-&gt;id ])}}<span class="hljs-string">" class="</span>main-card-btn<span class="hljs-string"><span class="hljs-string">"&gt;阅读更多&lt;/a&gt;</span></span></div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="41"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line"><span class="hljs-string">            &lt;/div&gt;</span></div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="42"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line"><span class="hljs-string">          &lt;/div&gt;</span></div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="43"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line"><span class="hljs-string">          @endforeach</span></div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="44"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line"><span class="hljs-string">        &lt;/div&gt;</span></div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="45"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line"><span class="hljs-string">        {{ <span class="hljs-subst">$content</span>-&gt;links()}}</span></div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="46"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line"><span class="hljs-string">      &lt;/div&gt;</span></div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="47"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line"><span class="hljs-string">      &lt;div class="</span>col-md-<span class="hljs-number">3</span><span class="hljs-string"><span class="hljs-string">"&gt;</span></span></div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="48"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line"><span class="hljs-string">        &lt;!-- 侧边栏 --&gt;</span></div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="49"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line"><span class="hljs-string">        @include('public/sidebar')</span></div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="50"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line"><span class="hljs-string">      &lt;/div&gt;</span></div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="51"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line"><span class="hljs-string">    &lt;/div&gt;</span></div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="52"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line"><span class="hljs-string">  &lt;/div&gt;</span></div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="53"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line"><span class="hljs-string">&lt;/div&gt;</span></div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="54"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line"><span class="hljs-string">@include('public/footer')</span></div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="55"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line"><span class="hljs-string">&lt;/body&gt;</span></div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="56"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line"><span class="hljs-string">&lt;/html&gt;</span></div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="57"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line"><span class="hljs-string"></span></div></div></li></ol></code><div class="hljs-button {2}" data-title="复制" onclick="hljs.copyCode(event)"></div></pre> 
<p>（2）通过浏览器访问内容列表页，可看到其效果。</p> 
<h4 id="%E4%BA%8C%E3%80%81%E9%9D%A2%E5%8C%85%E5%B1%91%E5%AF%BC%E8%88%AA"><a name="t43"></a>二、面包屑导航</h4> 
<h5 id="1.%E5%AE%89%E8%A3%85">1.安装</h5> 
<p>（1）使用<strong>Composer</strong>载入<strong>laravel-breadcrumbs</strong>库，具体代码如下：</p> 
<pre data-index="139" class="set-code-show" name="code"><code class="language-php hljs">composer <span class="hljs-keyword">require</span> davejamesmiller/laravel-breadcrumbs</code><div class="hljs-button {2}" data-title="复制" onclick="hljs.copyCode(event)"></div></pre> 
<p>（2）在<strong>config\app.php</strong>文件中将这个服务提供者注册到Laravel中，具体代码如下：</p> 
<pre data-index="140" class="set-code-show" name="code"><code class="language-php hljs"><ol class="hljs-ln" style="width:100%"><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="1"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line">    <span class="hljs-string">'providers'</span> =&gt; [</div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="2"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line"> </div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="3"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line">        ...（原有代码）</div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="4"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line">        <span class="hljs-title class_">DaveJamesMiller\Breadcrumbs\BreadcrumbsServiceProvider</span>::<span class="hljs-variable language_">class</span>,</div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="5"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line"> </div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="6"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line">    ],</div></div></li></ol></code><div class="hljs-button {2}" data-title="复制" onclick="hljs.copyCode(event)"></div></pre> 
<p>(3)在<strong>config\app.php</strong>文件中注册别名，以方便使用，具体代码如下：</p> 
<pre data-index="141" class="set-code-show" name="code"><code class="language-php hljs"><ol class="hljs-ln" style="width:100%"><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="1"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line"> <span class="hljs-string">'aliases'</span> =&gt; [</div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="2"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line"> </div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="3"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line">        ...(原有代码)</div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="4"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line">        <span class="hljs-string">'Breadcrumbs'</span> =&gt; <span class="hljs-title class_">DaveJamesMiller\Breadcrumbs\Facades\Breadcrumbs</span>::<span class="hljs-variable language_">class</span>,</div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="5"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line"> </div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="6"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line">    ],</div></div></li></ol></code><div class="hljs-button {2}" data-title="复制" onclick="hljs.copyCode(event)"></div></pre> 
<h5 id="2.%E9%85%8D%E7%BD%AE%E5%AF%BC%E8%88%AA">2.配置导航</h5> 
<p>（1）配置首页的导航链接，创建<strong>routes\breadcrumbs.php</strong>文件，具体代码如下：</p> 
<pre data-index="142" class="set-code-show" name="code"><code class="language-php hljs"><ol class="hljs-ln" style="width:100%"><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="1"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line"><span class="hljs-meta">&lt;?php</span></div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="2"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line"><span class="hljs-keyword">use</span> <span class="hljs-title">DaveJamesMiller</span>\<span class="hljs-title">Breadcrumbs</span>\<span class="hljs-title">Facades</span>\<span class="hljs-title">Breadcrumbs</span>;</div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="3"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line"><span class="hljs-keyword">use</span> <span class="hljs-title">App</span>\<span class="hljs-title">Category</span>;</div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="4"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line"><span class="hljs-keyword">use</span> <span class="hljs-title">App</span>\<span class="hljs-title">Content</span>;</div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="5"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line"> </div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="6"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line"><span class="hljs-title class_">Breadcrumbs</span>::<span class="hljs-title function_ invoke__">register</span>(<span class="hljs-string">'home'</span>, function(<span class="hljs-variable">$breadcrumbs</span>){</div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="7"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line">    <span class="hljs-variable">$breadcrumbs</span>-&gt;<span class="hljs-title function_ invoke__">push</span>(<span class="hljs-string">'首页'</span>, <span class="hljs-title function_ invoke__">route</span>(<span class="hljs-string">'home'</span>));</div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="8"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line">});</div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="9"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line"> </div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="10"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line"><span class="hljs-title class_">Breadcrumbs</span>::<span class="hljs-title function_ invoke__">register</span>(<span class="hljs-string">'category'</span>, function (<span class="hljs-variable">$breadcrumbs</span>, <span class="hljs-variable">$id</span>) {</div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="11"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line">    <span class="hljs-variable">$category</span> = <span class="hljs-title class_">Category</span>::<span class="hljs-title function_ invoke__">find</span>(<span class="hljs-variable">$id</span>);</div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="12"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line">    <span class="hljs-variable">$breadcrumbs</span>-&gt;<span class="hljs-built_in">parent</span>(<span class="hljs-string">'home'</span>);</div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="13"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line">    <span class="hljs-variable">$breadcrumbs</span>-&gt;<span class="hljs-title function_ invoke__">push</span>(<span class="hljs-variable">$category</span>-&gt;name, <span class="hljs-title function_ invoke__">route</span>(<span class="hljs-string">'category'</span>, <span class="hljs-variable">$id</span>));</div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="14"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line">});</div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="15"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line"> </div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="16"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line"><span class="hljs-title class_">Breadcrumbs</span>::<span class="hljs-title function_ invoke__">register</span>(<span class="hljs-string">'detail'</span>, function (<span class="hljs-variable">$breadcrumbs</span>, <span class="hljs-variable">$posts</span>) {</div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="17"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line">    <span class="hljs-variable">$content</span> = <span class="hljs-title class_">Content</span>::<span class="hljs-title function_ invoke__">find</span>(<span class="hljs-variable">$posts</span>[<span class="hljs-string">'id'</span>]);</div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="18"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line">    <span class="hljs-variable">$breadcrumbs</span>-&gt;<span class="hljs-built_in">parent</span>(<span class="hljs-string">'category'</span>, <span class="hljs-variable">$posts</span>[<span class="hljs-string">'cid'</span>]);</div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="19"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line">    <span class="hljs-variable">$breadcrumbs</span>-&gt;<span class="hljs-title function_ invoke__">push</span>(<span class="hljs-variable">$content</span>-&gt;title, <span class="hljs-title function_ invoke__">route</span>(<span class="hljs-string">'detail'</span>, <span class="hljs-variable">$posts</span>[<span class="hljs-string">'id'</span>]));</div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="20"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line">});</div></div></li></ol></code><div class="hljs-button {2}" data-title="复制" onclick="hljs.copyCode(event)"></div></pre> 
<p>（2）通过浏览器访问内容列表页，查看面包屑导航效果。</p> 
<h3 id="%E5%86%85%E5%AE%B9%E5%B1%95%E7%A4%BA"><a name="t44"></a>内容展示</h3> 
<h4 id="%E4%B8%80%E3%80%81%E5%86%85%E5%AE%B9%E8%AF%A6%E7%BB%86%E9%A1%B5"><a name="t45"></a>一、内容详细页</h4> 
<p>在<strong>resources\views</strong>目录下创建<strong>detail.blade.php</strong>,具体代码如下：</p> 
<pre data-index="143" class="set-code-show" name="code"><code class="language-php hljs"><ol class="hljs-ln hundred" style="width:100%"><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="1"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line">&lt;!DOCTYPE html&gt;</div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="2"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line">&lt;html&gt;</div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="3"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line">&lt;head&gt;</div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="4"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line">  @<span class="hljs-keyword">include</span>(<span class="hljs-string">'public/static'</span>)</div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="5"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line">  &lt;title&gt;详细页&lt;/title&gt;</div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="6"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line">&lt;/head&gt;</div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="7"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line">&lt;body&gt;</div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="8"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line">@<span class="hljs-keyword">include</span>(<span class="hljs-string">'public/header'</span>)</div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="9"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line">&lt;div <span class="hljs-class"><span class="hljs-class"><span class="hljs-keyword">class</span>="<span class="hljs-title">main</span>"&gt;</span></span></div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="10"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line"><span class="hljs-class">  &lt;<span class="hljs-title">div</span> <span class="hljs-title">class</span>="<span class="hljs-title">main</span>-<span class="hljs-title">crumb</span>"&gt;</span></div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="11"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line"><span class="hljs-class">    &lt;<span class="hljs-title">div</span> <span class="hljs-title">class</span>="<span class="hljs-title">container</span>"&gt;</span></div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="12"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line"><span class="hljs-class">      &lt;!-- 面包屑导航 --&gt;</span></div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="13"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line"><span class="hljs-class">      &lt;<span class="hljs-title">nav</span> <span class="hljs-title">aria</span>-<span class="hljs-title">label</span>="<span class="hljs-title">breadcrumb</span>"&gt;</span></div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="14"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line"><span class="hljs-class">        </span>{!! <span class="hljs-title class_">Breadcrumbs</span>::<span class="hljs-title function_ invoke__">render</span>(<span class="hljs-string">'detail'</span>, [<span class="hljs-string">'id'</span>=&gt;<span class="hljs-variable">$id</span>,<span class="hljs-string">'cid'</span>=&gt;<span class="hljs-variable">$cid</span>]); !!}</div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="15"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line">      &lt;/nav&gt;</div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="16"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line">    &lt;/div&gt;</div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="17"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line">  &lt;/div&gt;</div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="18"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line">  &lt;div <span class="hljs-class"><span class="hljs-class"><span class="hljs-keyword">class</span>="<span class="hljs-title">container</span>"&gt;</span></span></div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="19"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line"><span class="hljs-class">    &lt;<span class="hljs-title">div</span> <span class="hljs-title">class</span>="<span class="hljs-title">row</span>"&gt;</span></div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="20"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line"><span class="hljs-class">      &lt;<span class="hljs-title">div</span> <span class="hljs-title">class</span>="<span class="hljs-title">col</span>-<span class="hljs-title">md</span>-9"&gt;</span></div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="21"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line"><span class="hljs-class">        &lt;!-- 内容区域 --&gt;</span></div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="22"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line"><span class="hljs-class">        &lt;<span class="hljs-title">article</span> <span class="hljs-title">class</span>="<span class="hljs-title">main</span>-<span class="hljs-title">article</span>"&gt;</span></div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="23"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line"><span class="hljs-class">          &lt;<span class="hljs-title">header</span>&gt;</span></div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="24"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line"><span class="hljs-class">            &lt;<span class="hljs-title">h1</span>&gt;</span>{{<span class="hljs-variable">$content</span>-&gt;title}}&lt;/h1&gt;</div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="25"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line">            &lt;div&gt;发表于{{ <span class="hljs-title function_ invoke__">date</span>(<span class="hljs-string">'Y-m-d'</span>, <span class="hljs-title function_ invoke__">strtotime</span>(<span class="hljs-variable">$content</span>-&gt;create_time)) }}&lt;/div&gt;</div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="26"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line">          &lt;/header&gt;</div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="27"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line">          &lt;div <span class="hljs-class"><span class="hljs-class"><span class="hljs-keyword">class</span>="<span class="hljs-title">main</span>-<span class="hljs-title">article</span>-<span class="hljs-title">content</span>"&gt;</span></span></div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="28"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line"><span class="hljs-class">            &lt;<span class="hljs-title">p</span>&gt;&lt;<span class="hljs-title">img</span> <span class="hljs-title">class</span>="<span class="hljs-title">img</span>-<span class="hljs-title">fluid</span>" <span class="hljs-title">src</span>="/<span class="hljs-title">static</span>/<span class="hljs-title">upload</span>/</span>{{<span class="hljs-variable">$content</span>-&gt;image}}<span class="hljs-string"><span class="hljs-string">"&gt;&lt;/p&gt;</span></span></div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="29"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line"><span class="hljs-string">            &lt;p&gt;{!! <span class="hljs-subst">$content</span>-&gt;content !!}&lt;/p&gt;</span></div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="30"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line"><span class="hljs-string">          &lt;/div&gt;</span></div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="31"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line"><span class="hljs-string">          &lt;!-- 点赞模块 --&gt;</span></div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="32"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line"><span class="hljs-string">          @if(session()-&gt;has('users'))</span></div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="33"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line"><span class="hljs-string">            &lt;div class="</span>main-article-like<span class="hljs-string"><span class="hljs-string">"&gt;</span></span></div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="34"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line"><span class="hljs-string">              &lt;span&gt;</span></div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="35"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line"><span class="hljs-string">              &lt;i class="</span>fa fa-thumbs-up<span class="hljs-string">" aria-hidden="</span><span class="hljs-literal">true</span><span class="hljs-string"><span class="hljs-string">"&gt;{<span class="hljs-subst">{$count}</span>}&lt;/i&gt;</span></span></div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="36"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line"><span class="hljs-string">              &lt;/span&gt;</span></div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="37"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line"><span class="hljs-string">            &lt;/div&gt;</span></div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="38"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line"><span class="hljs-string">          @endif</span></div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="39"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line"><span class="hljs-string">        &lt;/article&gt;</span></div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="40"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line"><span class="hljs-string">        &lt;div class="</span>main-comment<span class="hljs-string"><span class="hljs-string">"&gt;</span></span></div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="41"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line"><span class="hljs-string">          &lt;!-- 评论列表 --&gt;</span></div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="42"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line"><span class="hljs-string">          @if(!<span class="hljs-subst">$comments</span>-&gt;isEmpty())</span></div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="43"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line"><span class="hljs-string">            &lt;div class="</span>main-comment-header<span class="hljs-string"><span class="hljs-string">"&gt;</span></span></div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="44"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line"><span class="hljs-string">              &lt;span id="</span>count<span class="hljs-string"><span class="hljs-string">"&gt;{<span class="hljs-subst">{$comments-&gt;count()}</span>}&lt;/span&gt; 条评论</span></span></div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="45"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line"><span class="hljs-string">            &lt;/div&gt;</span></div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="46"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line"><span class="hljs-string">            @foreach(<span class="hljs-subst">$comments</span> as <span class="hljs-subst">$val</span>)</span></div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="47"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line"><span class="hljs-string">              &lt;div class="</span>main-comment-item<span class="hljs-string"><span class="hljs-string">"&gt;</span></span></div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="48"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line"><span class="hljs-string">                &lt;div class="</span>main-comment-name<span class="hljs-string"><span class="hljs-string">"&gt;{<span class="hljs-subst">{$val-&gt;user-&gt;name}</span>}&lt;/div&gt;</span></span></div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="49"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line"><span class="hljs-string">                &lt;div class="</span>main-comment-date<span class="hljs-string"><span class="hljs-string">"&gt;</span></span></div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="50"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line"><span class="hljs-string">                  {{ date('Y-m-d', strtotime(<span class="hljs-subst">$val</span>-&gt;created_at)) }}&lt;/div&gt;</span></div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="51"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line"><span class="hljs-string">                &lt;div class="</span>main-comment-content<span class="hljs-string"><span class="hljs-string">"&gt;{<span class="hljs-subst">{$val-&gt;content}</span>}&lt;/div&gt;</span></span></div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="52"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line"><span class="hljs-string">              &lt;/div&gt;</span></div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="53"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line"><span class="hljs-string">            @endforeach</span></div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="54"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line"><span class="hljs-string">          @endif</span></div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="55"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line"><span class="hljs-string">        &lt;/div&gt;</span></div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="56"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line"><span class="hljs-string">        &lt;!-- 发表评论模块 --&gt;</span></div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="57"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line"><span class="hljs-string">        &lt;div class="</span>main-reply<span class="hljs-string"><span class="hljs-string">"&gt;</span></span></div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="58"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line"><span class="hljs-string">          @if(session()-&gt;has('users'))</span></div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="59"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line"><span class="hljs-string">            &lt;div class="</span>main-reply-header<span class="hljs-string"><span class="hljs-string">"&gt;发表评论&lt;/div&gt;</span></span></div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="60"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line"><span class="hljs-string">            &lt;div class="</span>main-reply-title<span class="hljs-string"><span class="hljs-string">"&gt;评论内容&lt;/div&gt;</span></span></div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="61"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line"><span class="hljs-string">            &lt;div&gt;&lt;textarea name="</span>content<span class="hljs-string">" rows="</span><span class="hljs-number">8</span><span class="hljs-string">" id="</span>content<span class="hljs-string"><span class="hljs-string">"&gt;&lt;/textarea&gt;&lt;/div&gt;</span></span></div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="62"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line"><span class="hljs-string">            &lt;div&gt;</span></div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="63"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line"><span class="hljs-string">              &lt;input type="</span>hidden<span class="hljs-string">" id='c_id' value="</span>{{<span class="hljs-variable">$id</span>}}<span class="hljs-string"><span class="hljs-string">"&gt;</span></span></div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="64"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line"><span class="hljs-string">              &lt;input type="</span>button<span class="hljs-string">" value="</span>提交评论<span class="hljs-string">" id="</span>publish<span class="hljs-string"><span class="hljs-string">"&gt;</span></span></div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="65"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line"><span class="hljs-string">            &lt;/div&gt;</span></div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="66"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line"><span class="hljs-string">          @endif</span></div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="67"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line"><span class="hljs-string">        &lt;/div&gt;</span></div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="68"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line"><span class="hljs-string">      &lt;/div&gt;</span></div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="69"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line"><span class="hljs-string">      &lt;div class="</span>col-md-<span class="hljs-number">3</span><span class="hljs-string"><span class="hljs-string">"&gt;</span></span></div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="70"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line"><span class="hljs-string">        &lt;!-- 侧边栏 --&gt;</span></div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="71"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line"><span class="hljs-string">        @include('public/sidebar')</span></div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="72"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line"><span class="hljs-string">      &lt;/div&gt;</span></div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="73"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line"><span class="hljs-string">    &lt;/div&gt;</span></div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="74"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line"><span class="hljs-string">  &lt;/div&gt;</span></div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="75"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line"><span class="hljs-string">&lt;/div&gt;</span></div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="76"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line"><span class="hljs-string">@include('public/footer')</span></div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="77"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line"><span class="hljs-string">&lt;/body&gt;</span></div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="78"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line"><span class="hljs-string">&lt;script&gt;</span></div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="79"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line"><span class="hljs-string">  $(document).ready(function() {</span></div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="80"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line"><span class="hljs-string">    $("</span>.fa-thumbs-up<span class="hljs-string">").bind("</span>click<span class="hljs-string"><span class="hljs-string">", function () {</span></span></div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="81"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line"><span class="hljs-string">      $.get("</span>{{ <span class="hljs-title function_ invoke__">url</span>(<span class="hljs-string">'like'</span>, <span class="hljs-variable">$id</span>) }}<span class="hljs-string"><span class="hljs-string">", {}, function (result) {</span></span></div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="82"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line"><span class="hljs-string">        var count = result.count;</span></div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="83"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line"><span class="hljs-string">        $("</span>.fa-thumbs-up<span class="hljs-string"><span class="hljs-string">").html();</span></span></div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="84"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line"><span class="hljs-string">        $("</span>.fa-thumbs-up<span class="hljs-string"><span class="hljs-string">").html(count);</span></span></div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="85"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line"><span class="hljs-string">      });</span></div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="86"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line"><span class="hljs-string">    });</span></div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="87"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line"><span class="hljs-string"></span></div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="88"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line"><span class="hljs-string">    $('#publish').bind("</span>click<span class="hljs-string"><span class="hljs-string">",function(){</span></span></div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="89"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line"><span class="hljs-string">      var data = {</span></div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="90"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line"><span class="hljs-string">        'cid' : $("</span><span class="hljs-comment">#c_id").val(),</span></div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="91"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line">        <span class="hljs-string">'content'</span> : $(<span class="hljs-string">"#content"</span>).<span class="hljs-title function_ invoke__">val</span>()</div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="92"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line">      };</div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="93"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line">      $.<span class="hljs-title function_ invoke__">get</span>(<span class="hljs-string">"{{ url('comment') }}"</span>,data, function(result){</div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="94"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line">        <span class="hljs-keyword">var</span> data = result.data;</div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="95"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line">        <span class="hljs-keyword">var</span> user = data.user;</div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="96"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line">        <span class="hljs-keyword">var</span> html = <span class="hljs-string">'&lt;div class="main-comment-item"&gt;'</span>;</div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="97"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line">        html += <span class="hljs-string">'&lt;div class="main-comment-name"&gt;'</span> + user[<span class="hljs-string">'name'</span>] + <span class="hljs-string">'&lt;/div&gt;'</span>;</div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="98"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line">        html += <span class="hljs-string">'&lt;div class="main-comment-date"&gt;'</span>;</div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="99"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line">        html += data[<span class="hljs-string">'created_time'</span>];</div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="100"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line">        html += <span class="hljs-string">'&lt;/div&gt;'</span>;</div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="101"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line">        html += <span class="hljs-string">'&lt;div class="main-comment-content"&gt;'</span>;</div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="102"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line">        html += data[<span class="hljs-string">'content'</span>] + <span class="hljs-string">'&lt;/div&gt;'</span>;</div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="103"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line">        html += <span class="hljs-string">'&lt;/div&gt;'</span>;</div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="104"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line">        $(<span class="hljs-string">".main-comment"</span>).<span class="hljs-title function_ invoke__">append</span>(html);</div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="105"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line">        $(<span class="hljs-string">"#count"</span>).<span class="hljs-title function_ invoke__">html</span>();</div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="106"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line">        $(<span class="hljs-string">"#count"</span>).<span class="hljs-title function_ invoke__">html</span>(data[<span class="hljs-string">'count'</span>]);</div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="107"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line">      });</div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="108"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line">    });</div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="109"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line">  });</div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="110"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line">&lt;/script&gt;</div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="111"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line">&lt;/html&gt;</div></div></li></ol></code><div class="hljs-button {2}" data-title="复制" onclick="hljs.copyCode(event)"></div></pre> 
<h3 id="articleContentId"><a name="t46"></a></h3>
                </div><div data-report-view="{&quot;mod&quot;:&quot;1585297308_001&quot;,&quot;spm&quot;:&quot;1001.2101.3001.6548&quot;,&quot;dest&quot;:&quot;https://blog.csdn.net/qq_64047601/article/details/131222336&quot;,&quot;extend1&quot;:&quot;pc&quot;,&quot;ab&quot;:&quot;new&quot;}"><div></div></div>
        </div>
            </div> 
            
              </main>     
       </body>
       </html>
    
            